Exec task not executing

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?

The snippet is not working because you call execute() explicitly. This is an internal method you should instead run task3_$env from the commandline using gradle task3_$env This way, gradle will ensure the dependent tasks get executed too.

But dependent tasks are called. If I try printing something from task1 and task2, this shows in stdout. It’s only that what’s specified in “commandLine” parameter isn’t executed. I’m not sure that this behavior is caused by using execute()…