I have a method with three dynamic Exec tasks that depend on each other. It looks something like this:
def method1(){ def env = getEnvironmentVariables(release) task ("task1_$env", type: Exec) { .... } task ("task2_$env", type: Exec, dependsOn: "task1_$env") { .... } task ("task3_$env", type: Exec, dependsOn: "task2_$env") { .... }.execute() }
When I execute this, task3 calls task2 (if I add “println” there, it executes), but command that task2 should execute is not fired.
I solved this problem this way:
def method1(){ def env = getEnvironmentVariables(release) task ("task1_$env", type: Exec) { .... } task ("task3_$env", type: Exec) { .... } task ("task2_$env", type: Exec) { .... doFirst{tasks["task1_$env"].execute()} doLast{tasks["task3_$env"].execute()}}.execute() }
but this is just a workaround.
Can someone help me understand why the first snippet didn’t work?