Extending Gradle with a Custom Enhanced Task: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 8: Line 8:


The simplest way of extending Gradle is write a custom [[Gradle_Task#Overview|task]]. The custom task can be declared [[Extending_Gradle#In-line_in_build.gradle|in-line in the default build script build.gradle]], as a [[#Simple_Task|simple task]]. The [[#Simple_Task|simple task]] can also be declared [[Extending_Gradle#In-line_in_a_script_plugin|in-line in a separate build script]], which is then included from the default build script. The code of the custom task can live in a separate source file, which in turn can be declared in [[Extending_Gradle#In_the_Project.27s_buildSrc_Directory|a special area of the Gradle project]], or can be shared with other projects as part of a library, developed in [[Extending_Gradle#External_to_Project|its own project]]. Such a task is referred to as a [[#Enhanced_Task|enhanced task]].
The simplest way of extending Gradle is write a custom [[Gradle_Task#Overview|task]]. The custom task can be declared [[Extending_Gradle#In-line_in_build.gradle|in-line in the default build script build.gradle]], as a [[#Simple_Task|simple task]]. The [[#Simple_Task|simple task]] can also be declared [[Extending_Gradle#In-line_in_a_script_plugin|in-line in a separate build script]], which is then included from the default build script. The code of the custom task can live in a separate source file, which in turn can be declared in [[Extending_Gradle#In_the_Project.27s_buildSrc_Directory|a special area of the Gradle project]], or can be shared with other projects as part of a library, developed in [[Extending_Gradle#External_to_Project|its own project]]. Such a task is referred to as a [[#Enhanced_Task|enhanced task]].
[[Gradle Task|Task]].
<font color=orange>DEPLETE [[Gradle_Task_TODEPLETE#Explicit_Task_Declaration_.28Custom_Tasks.29]]</font>


=Simple Task=
=Simple Task=

Revision as of 06:38, 24 September 2020

External

Internal

Overview

The simplest way of extending Gradle is write a custom task. The custom task can be declared in-line in the default build script build.gradle, as a simple task. The simple task can also be declared in-line in a separate build script, which is then included from the default build script. The code of the custom task can live in a separate source file, which in turn can be declared in a special area of the Gradle project, or can be shared with other projects as part of a library, developed in its own project. Such a task is referred to as a enhanced task.

Simple Task

A simple task is defined with an in-line task action closure in the build script or another script imported from the build script.

task customSimpleTask {
    println 'this is a simple task'
}

Enhanced Task

An enhanced task implies writing code into a source code file (or files) and providing that bytecode to Gradle. The behavior is built into the task and the task exposes some properties that can be configured from the build script. This is appropriate if the task needs to be shared across different projects.