I have a gradle project that has a calculated variable I need to pass into an application. When i attempt to do this is passes a null value, not the set value I want.
I have the below example file that demonstrates the issue to run just do gradle foo I want both lines of output to be 4.
def String sum
task add {
doLast {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'sh'
args = ['-c', 'echo $((2 + 2))']
standardOutput = os
}
sum = os.toString()
afterEvaluate {
tasks.foo {
systemProperty "foo.bar", "${sum}"
}
}
}
}
}
task foo {
doLast{
println System.properties['foo.bar']
println "${sum}"
}
}
tasks.foo.dependsOn( add )