Why Does Ant Sub-Task Execute

(Dennis Gesker) #1


I’m using 2.12 and I’m trying to disable a task. My actual task is more complicated. But, below is my test case.

I would think if myTask is (dis)abled – enabled == false – the task and nothing within it should run but I’m not seeing that behavior.

I could use a hint…


task myTask(){
     enabled = false
     ant.echo('Hello') //<-- Why does this print when enabled == false for myTask()?

    enabled = false

(Dennis Gesker) #2

Forgot to mention my environment: Openjdk-8 build 8u77, Ubuntu Linux 16.04 &

(Sterling Greene) #3

You’re mixing up the configuration phase from the execution phase. See https://docs.gradle.org/current/userguide/build_lifecycle.html

Gradle executes ant.echo during the configuration phase because it’s inside myTask's configuration block.

If you want ant.echo to only come out when myTask is executed, you need to put it in an action:

task myTask() {
   doLast {

(Dennis Gesker) #4

Thank you Mr. Green! I very much appreciate the tip. Just what I needed.