Gradle - Task


A build process execute a graph of tasks.

Task may just be:


tasks.register("Hello") {
gradlew Hello


Tasks themselves consist of:

  • Actions — pieces of work that do something, like copy files or compile source
  • Inputs — values, files and directories that the actions use or operate on
  • Outputs — files and directories that the actions modify or generate

A task should never call another task.

Tasks should define inputs and outputs to get the performance benefits of incremental build functionality.


When declaring the outputs of a task, make sure that the directory for writing outputs is unique among all the tasks in your project.

Intermingling or overwriting output files produced by different tasks compromises up-to-date checking causing slower builds. In turn, these filesystem changes may prevent Gradle’s build cache from properly identifying and caching what would otherwise be cacheable tasks.



Task are provided by:


Example for copy

task copy(type: Copy, group: "Custom", description: "Copies sources to the dest directory") {
    from "src"
    into "dest"



tasks.register("logInfo") {
  doFirst {
    println("A task message which is logged at INFO level")


task echo(description: 'Default task') << {
    println 'Hello'
defaultTasks 'echo'


  • In one project directory
gradlew tasks 
# or
gradlew tasks --all
gradle :services:webservice:tasks


tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
  • Lookup
val testTask =  tasks.getByName<Test>("test");
testTask.failFast = true;
  • Or declarative
tasks.test {
   failFast = true;


gradle -q taskName


  • -q stands for quiet


  • Specify a task to be excluded from execution.
gradle [-x|--exclude-task]


Ignore previously cached task results.

gradle --rerun-tasks


gradlew help --task <task>


Run the builds with all task actions disabled.

gradle [-m|--dry-run]


tasks.register("hello") {
    doLast {
        println("Hello world!")
tasks.register("intro") {
    doLast {
        println("I'm Gradle")


See Gradle - Cache (.gradle)

Discover More
Card Puncher Data Processing

gradle is a build tool that can run: a build (a set of tasks) or a single task gradle/gradle/
Gradle - Api

The gradle api is the core module of Gradle and provides task. The API can be seen in the lang reference
Gradle - Build

A build is a lifecyle task that executes a graph of task Gradle executes build scripts in three fixed phases: Initialization: Sets up the environment for the build and determine which projects will...
Gradle - Cache (.gradle)

Defaults to .gradle in the root project directory. Specify the project-specific cache directory. Ignore previously cached task results. Disables the Gradle build cache. Enables the Gradle...
Gradle - Dependency

dependency management in Gradle of module Type Module...
Gradle - Graph of Task (Dag)

A build execute a graph (dag) of task. This dag is build itself in the second phase of the build execution.
Gradle - Plugin

plugin adds task to Gradle. A gradle distribution comes out of the box with: the base. the gradle core task api. (Ref)...
Gradle - Project Property

Project property is a type property that has a project scope You can access a project property in your build script simply by using its name as you would use a variable. Example: project property...
How to skip a task if another task is executed in Gradle?

This page shows you how you can skip a task if another task is executed. It can happen in a test development when you have some build task you don't want to execute in a dev setting but that you want...
JavaExec - How to execute a main class from the command line with Gradle

The below build file define a JavaExec task with the name myCli and set: the main class the class path the current directory the arguments The dos script that calls the task myCli. This file...

Share this page:
Follow us:
Task Runner