Change in projectsLoaded execution starting in 4.0


(Brian Johnson) #1

I have some special setup code that was working up through Gradle 3.5, and then broke in 4.0. I haven’t been able to find anything in the release notes for 4.0 that would explain the change. Hoping someone can help me identify what’s going wrong.

What we’re trying to accomplish here is to set an extra property on the root project before it (and all the subprojects) gets evaluated.

Here’s a very simplified example that demonstrates the change in behavior. The println statements are just for debug purposes.

settings.gradle:

rootProject.name = 'Test'
include ':subA'
gradle.projectsLoaded { g ->
    println "Inside projectsLoaded"
    g.rootProject {
        println "Inside rootProject"
        beforeEvaluate { project ->
            println "Inside beforeEvaluate"
            project.ext.extvar = 'Blah'
        }
    }
}

root build.gradle:

subprojects {
	println extvar
}

Here’s the output from running this with 3.5:

$ gradle --console=plain build
Inside projectsLoaded
Inside rootProject
Inside beforeEvaluate
Blah
:buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

classpath
No dependencies

BUILD SUCCESSFUL

Total time: 0.929 secs

And here’s the output from running it with 4.0. Notice how the debug statements stop after projectsLoaded.

$ gradle --console=plain build 
Inside projectsLoaded

FAILURE: Build failed with an exception.

* Where:
Build file '/home/bjohnson/gradletest/build.gradle' line: 2

* What went wrong:
A problem occurred evaluating root project 'Test'.
> Could not get unknown property 'extvar' for project ':subA' of type org.gradle.api.Project.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 1s

Any help in figuring out what changed between these two releases and how to improve/fix this code would be greatly appreciated. Thanks!


(Stefan Oehme) #2

This should work, can you please open a bug report?


(Brian Johnson) #3

Bug report has been opened: https://github.com/gradle/gradle/issues/2888
Thank you!