Dark theme | Light theme

October 13, 2010

Gradle Goodness: Group Similar Tasks

In Gradle we can assign a task to a group. Gradle uses the group for example in the output of $ gradle -t to output all the tasks of the same group together. We only have to set the group property with a value and our task belongs to a group.

In the following sample we add the tasks hello and bye to the group Greeting:

def GREETING_GROUP = 'Greeting'

task hello << {
   println 'Hello Gradle!'
hello.description = 'Say hello.'

task bye {
    description= 'Say goodbye.'
    group = GREETING_GROUP
bye << {
    println 'Goodbye.'

If we run $ gradle -t we get the following output:


Root Project

Greeting tasks
bye - Say goodbye.
hello - Say hello.

Help tasks
dependencies - Displays a list of the dependencies of root project 'taskgroup'.
help - Displays a help message
projects - Displays a list of the sub-projects of root project 'taskgroup'.
properties - Displays a list of the properties of root project 'taskgroup'.
tasks - Displays a list of the tasks in root project 'taskgroup'.

To see all tasks and more detail, run with --all.

Written with Gradle 0.9.