I have created a custom build script where I am setting certain project properties and then applying the build script into my primary build.gradle.
However, the properties are not available to me and I get the following exception :
cannot get property ‘XXXX’ on extra properties extension as it does not exist
Following is my test build.gradle
buildscript {
apply from : 'custom-build-script.gradle'
}
println "my property"+project.ext.XXXX
My custom-build-script.gradle looks like -
task config {
doFirst {
project.ext.set(XXXX,<value>)
}
}
I am not sure if my expectation is correct or if I am missing something here. Could anyone please provide me some pointers to resolve this.
Appreciate your help.
Thanks.
The code inside doFirst
defines an action that only runs if the config
task is built.
If custom-build-script.gradle
is just this one line, then it works:
project.ext.set('XXXX', 'foo')
Thanks Andrew.
There was a build script section as well in the custom-build-script.gradle.
I am not exactly sure of the concept here, but someone else suggested me to make the setting of the project properties inside a build-script section. I tried doing that and in my primary build.gradle, now I am able to see the project properties.
My primary build.gradle -
buildscript {
apply from : 'custom-build-script.gradle'
}
println "my property"+project.ext.XXXX
My custom-build-script.gradle now looks like -
buildscript {
repositories { //maven related info }
dependencies { //defined my dependencies }
properites.each { prop ->
project.ext.set(prop.key,prop.value)
}
}