List the tasks of a build

A task is the unit of work of a build, and every plugin adds a set of them. Before writing one, it is worth asking Gradle what is already there: three commands print the list, the list including the hidden ones, and the reference of a single task.

gradle tasks

settings.gradle

rootProject.name = 'shop'

build.gradle

plugins { id 'java' }

gradle tasks --console=plain --offline --no-daemon


> Task :tasks

------------------------------------------------------------
Tasks runnable from root project 'shop'
------------------------------------------------------------

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the classes of the 'main' feature.
testClasses - Assembles test classes.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
updateDaemonJvm - Generates or updates the Gradle Daemon JVM criteria.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the 'main' feature.

Help tasks
----------
artifactTransforms - Displays the Artifact Transforms that can be executed in root project 'shop'.
buildEnvironment - Displays all buildscript dependencies declared in root project 'shop'.
dependencies - Displays all dependencies declared in root project 'shop'.
dependencyInsight - Displays the insight into a specific dependency in root project 'shop'.
help - Displays a help message.
javaToolchains - Displays the detected java toolchains.
outgoingVariants - Displays the outgoing variants of root project 'shop'.
projects - Displays the sub-projects of root project 'shop'.
properties - Displays the properties of root project 'shop'.
resolvableConfigurations - Displays the configurations that can be resolved in root project 'shop'.
tasks - Displays the tasks runnable from root project 'shop'.

Verification tasks
------------------
check - Runs all checks.
test - Runs the test suite.

Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.

To see all tasks and more detail, run gradle tasks --all

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL in 12s
1 actionable task: 1 executed

The groups come from the java plugin and from Gradle itself: build holds what builds the project, build setup the tasks that write a build, documentation what writes a report, help the commands of the tool, and verification the checks. The Rules block at the end is different: those are task patterns, not tasks, and clean is one of them. A plugin of your own puts its tasks in a group of your own, and a task without a group appears only under --all.

The groups

The list is grouped, and the group of a task is a string: group = 'verification' in the task itself. Gradle only lists a task that has a description, so a task of your own needs both lines before it appears here; that is why the lessons that write a task always write the two together.

gradle tasks --all

--all adds the tasks without a group and the dependencies each one pulls in. The list of a Java project is long, so the excerpt below keeps the start of the build group and leaves the rest out; run the command to see all of it.

gradle tasks --all --group build --console=plain --offline --no-daemon


> Task :tasks

------------------------------------------------------------
Tasks runnable from root project 'shop'
------------------------------------------------------------

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the classes of the 'main' feature.
testClasses - Assembles test classes.

Other tasks
-----------
compileJava - Compiles main Java source.
compileTestJava - Compiles test Java source.
prepareKotlinBuildScriptModel
processResources - Processes main resources.
processTestResources - Processes test resources.

BUILD SUCCESSFUL in 12s
1 actionable task: 1 executed

gradle help --task

gradle help --task build --console=plain --offline --no-daemon


> Task :help
Detailed task information for build

Path
     :build (registered by plugin class 'org.gradle.language.base.plugins.LifecycleBasePlugin')

Type
     Task (org.gradle.api.Task)

Options
     --rerun Causes the task to be re-run even if up-to-date.

Description
     Assembles and tests this project.

Group
     build

BUILD SUCCESSFUL in 11s
1 actionable task: 1 executed

The answer names the path, the Java type of the task, its options, its description and its group. The type is the important line: it says which task class runs, and that class is where the inputs and the outputs are declared. For build the type is a lifecycle task, which does nothing itself and only depends on other tasks.

Related

Автор статьи: Arthur Isaev