Search code examples
gradlebuild.gradlegradlew

gradle - when i execute a task why is the configuration phase being called also


i have two tasks in my gradle file which looks like this:

    task aExecutionTask << {

    println 'hello says aExecutionTask, via the execution phase'

}




task aConfigurationTask{

    println 'hello says aConfigurationTask, via the configuration phase'


}

now from the command line i run: ./gradlew aExecutionTask and i was expecting it to only say the following:

hello says aExecutionTask, via the execution phase

but instead it ran both task and i got two print outs like this:

hello says aConfigurationTask, via the configuration phase
hello says aExecutionTask, via the execution phase

Why did it run the configuration phase when i am executing only the execution task using the << feature ? What if i want to run a task only and not have anything else called, how is that done ?

UPDATE: Thanks to the response here i wrote a blog to help anyone else:


Solution

  • Because the point of the configuration phase is to configure all the tasks, in order for gradle to know which tasks depend on which other tasks. That allows gradle to determine the directed acyclic graph of tasks.

    Then gradle determines, from the task you asked to execute and this DAG, which of the configured tasks must be executed, on which order, during the execution phase.