blach
(Simo Amini)
November 8, 2017, 1:30pm
1
I have two tasks that are executed one after the other, in the first I set a variable that I use in the second:
project.ext.set(“chain”, “empty”)
task swid {
project.ext.set(“chain”, “variant”)
}
task compile{
def propC = project.chain
println propC
}
I always get : empty
as a result
how can I change the variable value in the first task?
jjustinic
(James Justinic)
November 8, 2017, 10:50pm
2
The code provided will always return variant
, not empty
, so you might need to double check what you have provided. The code in both your tasks should be wrapped in a doLast { }
to execute with the task rather than at configuration time.
project.ext.set('chain', 'empty')
task swid {
doLast {
project.ext.set('chain', 'variant')
}
}
task compile {
doLast {
def propC = project.chain
println propC
}
}
If your description is accurate, it seems likely that you’re halfway there and swid
has doLast { }
, but compile
does not.
blach
(Simo Amini)
January 23, 2018, 9:26am
3
jjustinic:
l always return variant,
yes I missed the doLast{}, now it’s working perfectly