Learn Java

Default Task

Demo

See the example in default_task directory.

build.gradle :

defaultTasks 'clean', 'run'

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

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

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

Run command gradle -q and get the result:

Default Cleaning!
Default Running!

Explains

We can find:

  1. The default build file is build.gradle.
  2. The default task or tasks can be set via defaultTasks.
  3. The default tasks run in the order you set.

We practice to find defaultTasks in documentation and we find it's Project.defaultTasks.

void defaultTasks(String... defaultTasks)

Sets the names of the default tasks of this project. These are used when no tasks names are provided when starting the build.

Parameters: defaultTasks - The default task names.

We can also find that the argument defaultTasks is String ..., and we use the method in below way.

defaultTasks 'clean', 'run'

That's how we use array in groovy.