Reputation: 41
settings.gradle
include ':projectA',':projectB'
projectA/build.gradle
task task1() {
doFirst {
println 'setting project.ext.testProperty1'
project(':projectB').ext.testProperty1 = 'MyProperty'
}
}
task task2 (dependsOn: ['task1', ':projectB:task3']) {
doLast {
println "Executed project B Task3 from projectA task2"
}
}
projectB/build.gradle
task task3() {
doLast {
println "task3 from projectB"
println project(':projectB').ext.testProperty1
if(project(':projectB').ext.hasProperty("testProperty1")) {
ext.prop1 = project.property("testProperty1")
println "+++++++++If : Clause++++++++++++++++++++++++++++++++"
} else {
println "+++++++++Else :Clause++++++++++++++++++++++++++++++++"
}
}
}
Now when I call gradle task2 the output I get is always
$ ../gradlew task2
:projectA:task1
setting project.ext.testProperty1
:projectB:task3
task3 from projectB
MyProperty
+++++++++Else :Clause++++++++++++++++++++++++++++++++
:projectA:task2
Executed project B Task3 from projectA task2
It never goes into the "If" Clause, what am I missing, It even seems to get the ext.property testProperty1 in ProjectB but hasProperties does not seem to evaluate it correctly.
Upvotes: 1
Views: 3018
Reputation: 41
If you take the "ext" out from the code
if(project(':projectB').ext.hasProperty("testProperty1"))
and instead change it to
if(project(':projectB').hasProperty("testProperty1"))
Then it goes to the if clause, I have no idea why having ext at readtime is causing an issue when we can use it at writetime.
Upvotes: 2