My build script has this code:
def includePatchFrom = "WTF?!"
task patchWebXml(type: Exec) {
executable "perl"
args "scripts/patch.pl", includePatchFrom
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(webtestWar)) {
includePatchFrom = "resources/webtest"
}
else {
includePatchFrom = "resources/production"
}
}
If I understand http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html correctly, I should be able to set that includePatchFrom variable in the whenReady closure, but it just keeps its initial value:
...
:patchWebXml
...
Starting process 'command 'perl''. Working directory: /Users/robert/ Command: perl scripts/patch.pl WTF?!
Successfully started process 'command 'perl''
Cannot read WTF?!: No such file or directory at scripts/patch.pl line 43, <$F> line 14.
:patchWebXml FAILED
From println statements I can tell that includePathFrom gets set to the correct value. It seems like the exec task already has used the old value of includePatchFrom and is not affected when the whenReady closure runs.
What am I missing here and how can I use a different patch file depending on whether this is a production or a test build?
taskGraph.whenReady happens much later than the configuration of the task. By then it's too late to change the value of the variable. Instead, you'll have to (re)configure the task directly (patchWebXml.args ...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With