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:

view sourceprint?

00.def GREETING_GROUP = ‘Greeting‘

01.

02.task hello << {

03.println ‘Hello Gradle!‘

04.}

05.hello.group = GREETING_GROUP

06.hello.description = ‘Say hello.‘

07.

08.task bye {

09.description= ‘Say goodbye.‘

10.group = GREETING_GROUP

11.}

12.bye << {

13.println ‘Goodbye.‘

14.}

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

:tasks

------------------------------------------------------------

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.

时间: 2024-11-03 20:46:03

Gradle Goodness: Group Similar Tasks的相关文章

Gradle Goodness: Display Available Tasks

To see which tasks are available for our build we can run Gradle with the command-line option -t or --tasks. Gradle outputs the available tasks from our build script. By default only the tasks which are dependencies on other tasks are shown. To see a

Gradle Goodness: Automatic Clean Tasks

Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This task is able to remove any output files or directories we have defined for our task. For example we can assign an output file or directory to our task with

Gradle Goodness: Adding Tasks to a Predefined Group

In Gradle we can group related tasks using the group property of a task. We provide the name of our group and if we look at the output of the tasks task we can see our tasks grouped in section with the given name. In the next sample we create a new t

Gradle Goodness: Continue Build Even with Failed Tasks

If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have fast feedback of our build status. If we don't want to this and want Gradle to execute all tasks, even though some might have failed, we use the comman

Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. One of the ways to alter the build configuration is with initialization or init scripts. These are like other Gradle scripts but are executed before t

Gradle Goodness: Task Output Annotations Create Directory Automatically

Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of Gradle is incremental build support. With incremental build support a task is only executed if it is really necessary. For example if a task generate

Gradle Goodness: Copy Files with Filtering

Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filtering capabilities. This means we can change the contents of the files that are copied before they reach their new destination. We use the filter() method

Gradle Goodness: Changing Name of Default Build File

Gradle uses the name build.gradle as the default name for a build file. If we write our build code in a file build.gradle then we don't have to specify the build filename when we run tasks. We can create build files with a different name other than b

Gradle Goodness: Add Incremental Build Support to Tasks

Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unless it is necessary. We can help Gradle and configure our task so it is ready for an incremental build. Suppose we have a task that generates a file. T