Gradle Task: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:
A tasks belongs to a [[Gradle Project#Overview|project]]. Each project comes with a set of pre-defined, [[#Built-in_Tasks|built-in tasks]]. Each declared [[Gradle Plugin Concepts#Overview|plugin]] may add its own tasks. New [[Extending_Gradle_with_Custom_Tasks#Simple_Task|simple tasks]] can be declared in-line in [[build.gradle]] or in [[Gradle_Plugin_Concepts#Script_Plugin|script plugins]]. Tasks whose implementations are available on the build's classpath can be declared in build.gradle, as [[Extending_Gradle_with_Custom_Tasks#Enhanced_Task|enhanced tasks]], and thus made available for use. Tasks can even be fully defined in-line  or in script plugins, by providing the task code in-line in the script.
A tasks belongs to a [[Gradle Project#Overview|project]]. Each project comes with a set of pre-defined, [[#Built-in_Tasks|built-in tasks]]. Each declared [[Gradle Plugin Concepts#Overview|plugin]] may add its own tasks. New [[Extending_Gradle_with_Custom_Tasks#Simple_Task|simple tasks]] can be declared in-line in [[build.gradle]] or in [[Gradle_Plugin_Concepts#Script_Plugin|script plugins]]. Tasks whose implementations are available on the build's classpath can be declared in build.gradle, as [[Extending_Gradle_with_Custom_Tasks#Enhanced_Task|enhanced tasks]], and thus made available for use. Tasks can even be fully defined in-line  or in script plugins, by providing the task code in-line in the script.


Any task instance implements [https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html org.gradle.api.Task] interface. Most tasks extend [https://docs.gradle.org/current/javadoc/org/gradle/api/DefaultTask.html org.gradle.api.DefaultTask].
Any task instance implements [https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html org.gradle.api.Task] interface. Most tasks extend directly or indirectly [https://docs.gradle.org/current/javadoc/org/gradle/api/DefaultTask.html org.gradle.api.DefaultTask].


=Task API=
=Task API=

Revision as of 23:29, 3 October 2020

Internal

Overview

A task represents a well defined piece of work that is executing during a build, such as compiling Java classes or creating a distribution file. The goal of a Gradle execution, also known as a Gradle build, is to execute a set of tasks, in sequence.

A tasks belongs to a project. Each project comes with a set of pre-defined, built-in tasks. Each declared plugin may add its own tasks. New simple tasks can be declared in-line in build.gradle or in script plugins. Tasks whose implementations are available on the build's classpath can be declared in build.gradle, as enhanced tasks, and thus made available for use. Tasks can even be fully defined in-line or in script plugins, by providing the task code in-line in the script.

Any task instance implements org.gradle.api.Task interface. Most tasks extend directly or indirectly org.gradle.api.DefaultTask.

Task API

org.gradle.api.Task

Task DSL

Task

Task Structure

Task Name

Each task has a name, which is unique within the context of its owning project. The name must not contain dashes.

Task Path

A task path is the concatenation of the task owning project name and the task name, separated by the ":" character.

Declaring a Task

With DSL

Programmatically

Task Configuration Closure

Task Action

Task Action Closure

Task action closures can be used to define custom simple tasks, in-line in build.gradle or in a script plugin.

@TaskAction

Task Dependencies

Explicit Dependencies

Implicit Dependencies

Custom Tasks

Extending Gradle with Custom Tasks

Built-in Tasks

Each build exposes a set of built-in tasks, that can be used right away without any additional configuration or loading any plugin:

TO DEPLETE

Gradle Task TODEPLETE