Gradle executes all tasks?

It's a common pitfall:

task hello {
    println("Any code in here is about *configuring* the\
    task. By default, all tasks always get configured.")
    doLast {
        println("Any code in here is about *executing* the task.\
        This code only gets run if and when Gradle decides to execute the task.")
    }
}

The distinction between configuration phase and execution phase is probably the single most important concept to understand in Gradle. It can be confusing at first, and may go away in the future. A kind of analogue in the Ant/Maven world is that these tools first parse XML build scripts and build an object model (perhaps resolving some properties along the way), and only then execute the build.


Adding to Peter answer, If you want to execute all task , you can specify the defaultTasks list.

defaultTasks 'clean', 'run'

task clean {
    doLast {
        println 'Default Cleaning!'
    }
}

task run {
    doLast {
        println 'Default Running!'
    }
}

task other {
    doLast {
        println "I'm not a default task!"
    }
}

Output

Output of gradle -q
> gradle -q
Default Cleaning!
Default Running!

More details can be found here https://docs.gradle.org/current/userguide/tutorial_using_tasks.html

Tags:

Gradle