I want to share a task code between subprojects, however the task requires subprojects to provide a specific property. How do I get this property in shared task?
root/build.gradle
subprojects { sub ->
task buildZip(type: Zip, dependsOn: assemble) {
archiveName = "${sub.name}-${sub.foo}"
}
}
I tried to declare foo
property in root/subProj/build.gradle
in many different ways. I also tried to access the property as ${sub.ext.foo}
. None of it helped and the error is roughly the same:
Could not get unknown property 'foo' for project ':subProj' of type org.gradle.api.Project.
How do I declare and access foo
property correctly?
In my understanding, the problem is that root script is executed first in configuration time and it cannot find the properties of not-yet-evaluated sub-projects. If so how do I access the properties lazily?