Search

Dark theme | Light theme

November 17, 2009

Gradle Goodness: Setting Default Tasks

To run a task with Gradle we must specify the task name as an argument. If we don't specify a task name we get an error that Gradle cannot determine a task to execute. We can define the tasks that need to be executed when we don't specify a task name explicitly. In a Gradle build script we invoke the method defaultTasks and pass the name or names of the tasks as arguments to the method. These tasks are executed when we run Gradle without any task name. When we run $ gradle -t or $ gradle --tasks we can see which tasks are the default tasks.

// File: build.gradle
usePlugin 'java'

defaultTasks 'clean', 'build'  // Run tasks clean and build if no task is specified.
$ gradle --tasks | grep "Default Tasks"
Default Tasks: clean, build

Written with Gradle 0.8.