MinecraftForge / ForgeGradle

Minecraft mod development framework used by Forge and FML for the gradle build system
GNU Lesser General Public License v2.1
509 stars 437 forks source link

Fix Gradle 8 warnings #812

Closed sciwhiz12 closed 1 year ago

sciwhiz12 commented 3 years ago

Lazily evaluate updated tokens map for run tasks

The updated tokens map is created by passing in the contents of the runtimeClasspath configuration. However, the run tasks are configured with the updated tokens map, which means the configuration is queried on configuration, which is deprecated and liable to be invalid in Gradle 8 according to [1] and the warnings when running FG.

To avoid resolving the configuration at configuration time, then, the updated tokens map is lazily created and used for configuring the run tasks.

The WrappedArgument class provides a way to lazily provide a (optionally post-processed) string, overriding the toString() method to return the string instead of the default object behavior. This allows us to pass the object directly into the various configuration methods of JavaExecSpec, which internally store Objects which are lazily toString()ed when the actual arguments/environment variables/system properties are needed for execution.

As far as I can tell, this is the only place we need to do this: while the configuration is also resolved as part of the individual IDE run configuration generation tasks, it is resolved within the task execution as opposed to the task configuration of the run tasks.

[1]: Gradle 7.1 User Guide, "Viewing and debugging dependencies", subsection "Resolving unsafe configuration resolution errors"

Add explicit task ordering to prevent Gradle dep. warnings

Gradle 7 now outputs more warnings for different wrong behaviors. One of these behaviors is when a task has an input set indirectly to the output of another task, without any ordering or dependency defined between them (whether via dependsOn, mustRunAfter, or passing a Provider from the output to the input).

To fix this, we define some tasks to mustRunAfter other tasks which produce their inputs without being connected via dependsOn or Providers. Through this, Gradle will ensure that the producing tasks run before the consuming tasks, but will not force the producers to run (which is what dependsOn specifies).

sciwhiz12 commented 1 year ago

Closing until a more comprehensive review can be done as to whether ForgeGrade 5 can be fitted to support Gradle 8. A future major version of FG will support Gradle 8.