# Why Does Ant Sub-Task Execute

**URL:** <https://discuss.gradle.org/t/why-does-ant-sub-task-execute/16717>\
**Category:** Help/Discuss\
**Created:** [April 18, 2016, 7:57pm UTC](https://discuss.gradle.org/t/why-does-ant-sub-task-execute/16717 "2016-04-18T19:57:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gesker](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gesker/32/5085_2.png) [@gesker](https://discuss.gradle.org/u/gesker)\
**Post date:** [April 18, 2016, 7:57pm UTC](https://discuss.gradle.org/t/why-does-ant-sub-task-execute/16717/1 "2016-04-18T19:57:27Z")

</div>

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

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

myTask{
    enabled = false
}

```

---

<div class="post-metadata">

**Author:** ![gesker](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gesker/32/5085_2.png) [@gesker](https://discuss.gradle.org/u/gesker)\
**Post date:** [April 18, 2016, 8:27pm UTC](https://discuss.gradle.org/t/why-does-ant-sub-task-execute/16717/2 "2016-04-18T20:27:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [April 20, 2016, 4:44am UTC](https://discuss.gradle.org/t/why-does-ant-sub-task-execute/16717/3 "2016-04-20T04:44:21Z")

</div>

You’re mixing up the configuration phase from the execution phase. See [https://docs.gradle.org/current/userguide/build\_lifecycle.html](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:

```gradle
task myTask() {
   doLast {
      ant.echo('Hello')
   }
}

```

---

<div class="post-metadata">

**Author:** ![gesker](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gesker/32/5085_2.png) [@gesker](https://discuss.gradle.org/u/gesker)\
**Post date:** [April 20, 2016, 6:58pm UTC](https://discuss.gradle.org/t/why-does-ant-sub-task-execute/16717/4 "2016-04-20T18:58:38Z")

</div>

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

Dennis
