Chapter 2. Gradle Tasks
Inside of a Gradle build file, the fundamental unit of build activity is the task. Tasks are named collections of build instructions that Gradle executes as it performs a build. You’ve already seen examples of tasks in Chapter 1, and they may seem like a familiar abstraction compared to other build systems, but Gradle provides a richer model than you may be used to. Rather than bare declarations of build activity tied together with dependencies, Gradle tasks are first-class objects available to you to program if you desire.
Let’s take a look at the different ways of defining a task, the two key aspects of task definitions, and the task API we can use to perform our own customization.
Declaring a Task
In the introduction, we saw how to create a task and assign it behavior all at the same time. However, there’s an even simpler way to create a task. All you need is a task name (Example 2-1).
taskhello
You can see the results of this by running gradle tasks (Example 2-2).
------------------------------------------------------------ Root Project ------------------------------------------------------------ Help tasks ---------- dependencies - Displays the dependencies of root project 'task-lab'. help - Displays a help message projects - Displays the subprojects of root project 'task-lab'. properties - Displays the properties of root project 'task-lab'. tasks - Displays the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access