Why Does Ant Sub-Task Execute


(Dennis Gesker) #1

Hello:

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…

Dennis

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

myTask{
    enabled = false
}

(Dennis Gesker) #2

Forgot to mention my environment: Openjdk-8 build 8u77, Ubuntu Linux 16.04 &
org.gradle.daemon=false
org.gradle.parallel=false


(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 {
      ant.echo('Hello')
   }
}

(Dennis Gesker) #4

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

Dennis