Change in projectsLoaded execution starting in 4.0

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: = '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

Root project

No dependencies


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.


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

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

Bug report has been opened:
Thank you!