Alex Beggs
09/04/2025, 3:31 PMJendrik Johannes
09/04/2025, 4:00 PMgradle.lifecycle.beforeProject
• Then you can access all information through that single-instance extension in all subprojects. (There should be no issue with isolation, because the loading itself is done in the init phase which runs before the parallel configuration of projects.)
• Disadvantage: potentially more boilerplate/complexity (creating extension, registering it in one place, accessing it in anothers)
Option 2
• Load the custom properties individually in each subproject
• Setup can be simpler without extension -> load properties and use them directly
• Disadvantage: Multi loading of the same file. Gradle may still only load once if you load through providers.fileContents
(not sure if that is true, would like to know).
I am usually doing Option 2 but on the long run Option 1 feels cleaner.Vampire
09/04/2025, 4:02 PMVampire
09/04/2025, 4:02 PMVampire
09/04/2025, 4:03 PMVampire
09/04/2025, 4:03 PMVampire
09/04/2025, 4:04 PMValueSource
per property, or one for the properties you need at configuration time and one for the others and so on.Vampire
09/04/2025, 4:05 PMVampire
09/04/2025, 4:06 PMAlex Beggs
09/04/2025, 4:07 PM-PvariablethatIneveruse=whatever
that I never use and it affects the configuration cache. I would have hoped that it keeps track of that usage as inputs, but I guess it is much simpler than that.
One issue I ran into with Option 1, I was unable to cache the data outside of the scope gradle.lifecycle.beforeProject
, so unclear how to prevent reloading for each project. I got a serialization issue.Alex Beggs
09/04/2025, 4:11 PM* What went wrong:
Failed to notify build listener.
> Failed to isolate 'GradleLifecycle' action: cannot serialize Gradle script object references as these are not supported with the configuration cache.
Alex Beggs
09/04/2025, 4:11 PMvar j = 1
gradle.lifecycle.beforeProject {
println("Configuring project ${j++}: ${this.path}")
}
as an exampleAlex Beggs
09/04/2025, 4:11 PMVampire
09/04/2025, 4:16 PMI got a serialization issue.Your
j
is a top-level property in the script, that practically means it is a property of the instance of the class implementing the Script logic and that instance cannot be serialized.
You need to break this chain, for example like
object DoesNotNeedAScriptReference {
var j = 1
}
gradle.lifecycle.beforeProject {
println("Configuring project ${DoesNotNeedAScriptReference.j++}: ${this.path}")
}
Alex Beggs
09/04/2025, 4:16 PMVampire
09/04/2025, 4:17 PMI am currently able to send aAs far as I remember there is a ticket to improve this somewhere, but I don't find it right now.that I never use and it affects the configuration cache.-PvariablethatIneveruse=whatever
Alex Beggs
09/04/2025, 4:18 PMVampire
09/04/2025, 4:21 PMVampire
09/04/2025, 4:21 PM