Task

Lets create 'Hello world' type of task.

task helloWorld {
    doLast {
        println "Hello World!"
    }
}

When we run gradle tasks --all, we should be able to see that task among other project tasks.

Other tasks
-----------
helloWorld

We can try to execute the task and see what happens. The task prints out 'Hello world' message in console.

➜  gradle helloWorld

> Task :helloWorld
Hello World!


BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

Tasks using Ant

Ant is available in all Gradle builds.

Dynamic tasks

Taks can be created in dynamic way.

Run gradle tasks --all to get all the available tasks. We should be able to see dynamically created tasks there.

Task dependencies

Tasks can be dependent on other tasks. There can be no circular dependencies (Gradle needs to be able to create an acyclic dependency graph).

Task abbreviation

Almost all the tasks are executable by its abbreviation. If there is conflict in abbreviation uniqueness, Gradle fails to run the task.

Exclude task from execution

Use -x flag to say what tasks should be excluded from task execution.

Task graph

We can hook into the task execution graph.

Last updated

Was this helpful?