You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[6.0] Run prepare tasks are not available if Gradle is set to configure on demand #838
If org.gradle.configureondemand=true is present in gradle.properties, or if running the task with --configure-on-demand, running the prepareRunClient or any similar task in a multiproject setup will fail, saying that the task was not found in the project. This blocks running the game through Gradle, as the run tasks require these tasks.
This seems to be caused by our registration of the run configuration-related tasks1 during a Gradle#projectsEvaluated listener, which causes Gradle to not find the task when trying to execute.
Example
Take the following example:
tasks.create("task1") { group 'boop' }
afterEvaluate {
tasks.create("task2") { group 'boop' }
gradle.projectsEvaluated {
tasks.create("task3") { group 'boop' }
}
}
When running tasks to list out all tasks, all three tasks appear as expected. Yet running the last task, task3, while configuration on demand is enabled causes a build failure as Gradle cannot find the task, even though the first two tasks run successfully.
According to @OrionDevelopment2, this is because the "task tree evaluation happens in practice immediately after project evaluation, but before the afterEvaluate blocks run."
ForgeGradle
In ForgeGradle, we register our run config-related tasks in both userdev and patcherdev plugins by calling the Utils#createRunConfigTasks method from within a Project#afterEvaluate block (the area for task2's registration above), which itself calls RunConfigGenerator#createIDEGenRunsTasks from withn a Gradle#projectsEvaluated block (the area for task3's registration above) as well as registering the tasks for each RunConfig through successive calls to RunConfigGenerator#createRunTask.
This means that when configuration on demand is enabled, as seen in the example above, the run config-related tasks will fail to run due to them seemingly being nonexistent to Gradle.
Conclusions
Fixing this seems to be non-trivial -- the 'ideal' solution would be to modify RunConfig to be lazy and use Propertys, so they can be plugged into tasks lazily, but that involves understanding and replicating in some fashion the confusing mess that is RunConfig's merging system (which I have yet to figure out).
@OrionDevelopment's suggestion to fixing it would be to register the tasks as early as possible -- when the run configs are registered to their containers -- then using 'configuration tasks' which run before each run config task and configure them according to the RunConfig's information. That seems more plausible3, though someone will need to try implement that suggestion to see any possibly shortcomings or limitations.
This issue seems related to gradle/gradle#9489, which also relates to task execution troubles with configuration on demand and Gradle#projectsEvaluated.
Footnotes
The prepare* and run* tasks for each RunConfig, as well as the IDE run generation tasks -- genEclipseRuns, genIntellijRuns, and genVSCodeRuns. ↩
Out-of-scope for ForgeGradle 6 to support configuration on demand, but I'd like for ForgeGradle 7 to do so. I'll keep this open as a reminder to double-check multi-project compatibility.
changed the title [-]Run prepare tasks are not available if Gradle is set to configure on demand[/-][+][6.0] Run prepare tasks are not available if Gradle is set to configure on demand[/+]on Oct 7, 2025
Activity
sciwhiz12 commentedon Jun 18, 2022
This seems to be caused by our registration of the run configuration-related tasks1 during a
Gradle#projectsEvaluatedlistener, which causes Gradle to not find the task when trying to execute.Example
Take the following example:
When running
tasksto list out all tasks, all three tasks appear as expected. Yet running the last task,task3, while configuration on demand is enabled causes a build failure as Gradle cannot find the task, even though the first two tasks run successfully.According to @OrionDevelopment2, this is because the "task tree evaluation happens in practice immediately after project evaluation, but before the
afterEvaluateblocks run."ForgeGradle
In ForgeGradle, we register our run config-related tasks in both userdev and patcherdev plugins by calling the
Utils#createRunConfigTasksmethod from within aProject#afterEvaluateblock (the area fortask2's registration above), which itself callsRunConfigGenerator#createIDEGenRunsTasksfrom withn aGradle#projectsEvaluatedblock (the area fortask3's registration above) as well as registering the tasks for eachRunConfigthrough successive calls toRunConfigGenerator#createRunTask.This means that when configuration on demand is enabled, as seen in the example above, the run config-related tasks will fail to run due to them seemingly being nonexistent to Gradle.
Conclusions
Fixing this seems to be non-trivial -- the 'ideal' solution would be to modify
RunConfigto be lazy and usePropertys, so they can be plugged into tasks lazily, but that involves understanding and replicating in some fashion the confusing mess that isRunConfig's merging system (which I have yet to figure out).@OrionDevelopment's suggestion to fixing it would be to register the tasks as early as possible -- when the run configs are registered to their containers -- then using 'configuration tasks' which run before each run config task and configure them according to the
RunConfig's information. That seems more plausible3, though someone will need to try implement that suggestion to see any possibly shortcomings or limitations.This issue seems related to gradle/gradle#9489, which also relates to task execution troubles with configuration on demand and
Gradle#projectsEvaluated.Footnotes
The
prepare*andrun*tasks for eachRunConfig, as well as the IDE run generation tasks --genEclipseRuns,genIntellijRuns, andgenVSCodeRuns. ↩Taken from a discussion in Forgecord's
#gradlechannel. ↩Insofar that it requires less refactoring and breaking changes than refactoring the whole
RunConfigsystem. ↩remove gradle.configureondemand to work around a ForgeGradle bug
Jonathing commentedon Oct 7, 2025
Out-of-scope for ForgeGradle 6 to support configuration on demand, but I'd like for ForgeGradle 7 to do so. I'll keep this open as a reminder to double-check multi-project compatibility.
[-]Run prepare tasks are not available if Gradle is set to configure on demand[/-][+][6.0] Run prepare tasks are not available if Gradle is set to configure on demand[/+]Jonathing commentedon Oct 15, 2025
Superseded by #991. Please track that issue for updates on ForgeGradle 7's compatibility with Configure on Demand.