# Why is a task executed even if no one calls it?

**URL:** <https://discuss.gradle.org/t/why-is-a-task-executed-even-if-no-one-calls-it/5494>\
**Category:** Old Forum Archive\
**Created:** [January 24, 2013, 7:25pm UTC](https://discuss.gradle.org/t/why-is-a-task-executed-even-if-no-one-calls-it/5494 "2013-01-24T19:25:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Popov](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/igor_popov/32/661_2.png) [@Igor\_Popov](https://discuss.gradle.org/u/Igor_Popov)\
**Post date:** [January 24, 2013, 7:25pm UTC](https://discuss.gradle.org/t/why-is-a-task-executed-even-if-no-one-calls-it/5494/1 "2013-01-24T19:25:00Z")

</div>

I reduced the problem I have to the following code (smallest I could get to reproduce the issue):

```gradle
task clean {
                                                                                                                                                                                      println "Executing clean"
}
   task generateFile(dependsOn: 'clean') {
    println "Executing generateFile"
}

```

The output I get when I run:

```gradle
gradle -q clean

```

is:

```gradle
Executing clean
Executing generateFile

```

And the output I expect is:

```gradle
Executing clean

```

What am I missing? Why is that generateFile task executed even if I didn’t tell it to?!? Is this supposed to happen?

Note: I’m using gradle version 1.2 (but could reproduce it on 1.3)

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 24, 2013, 8:08pm UTC](https://discuss.gradle.org/t/why-is-a-task-executed-even-if-no-one-calls-it/5494/2 "2013-01-24T20:08:00Z")

</div>

Gradle has a _configuration_ phase and an _execution phase_. In the configuration phase, all tasks will get configured. In the execution phase, only a subset of tasks will get executed. Your ‘println’ statements are _configuring_ the tasks. Everything that the task is supposed to do at execution time needs to be wrapped in ‘doFirst { … }’ or ‘doLast { … }’. (For the latter, there is a ‘\<\<’ shortcut syntax, but using ‘doLast { … }’ is less error prone.) The [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html) has more on this.

---

<div class="post-metadata">

**Author:** ![djangofan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/djangofan/32/117_2.png) [@djangofan](https://discuss.gradle.org/u/djangofan)\
**Post date:** [January 24, 2013, 8:55pm UTC](https://discuss.gradle.org/t/why-is-a-task-executed-even-if-no-one-calls-it/5494/3 "2013-01-24T20:55:00Z")

</div>

Thanks for the good answer. I was wondering about that.

Would it be possible, or even practical, to turn off the standard output of the configuration phase through a config option?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 24, 2013, 9:02pm UTC](https://discuss.gradle.org/t/why-is-a-task-executed-even-if-no-one-calls-it/5494/4 "2013-01-24T21:02:00Z")

</div>

‘println’'s are logged on level ‘quiet’, hence they are even shown when running with ‘-q’. You can log using a lesser logging level with ‘log.debug’, ‘[log.info](http://log.info)’, or ‘log.lifecycle’.
