Executing multiple tasks
With just a simple build script, we already discussed that we have a couple of default tasks besides our own task that we can execute. To execute multiple tasks, we only have to add each task name to the command line. Let's execute our helloWorld
custom task and built-in tasks
task:
$ gradle helloWorld tasks :helloWorld Hello world. :tasks ------------------------------------------------------------ All tasks runnable from root project ------------------------------------------------------------ Build Setup tasks ----------------- init - Initializes a new Gradle build. [incubating] wrapper - Generates Gradle wrapper files. [incubating] Help tasks ---------- components - Displays the components produced by root project 'hello-world'. [incubating] dependencies - Displays all dependencies declared in root project 'hello-world'. dependencyInsight - Displays the insight into a specific dependency in root project 'hello-world'. help - Displays a help message. model - Displays the configuration model of root project 'hello-world'. [incubating] projects - Displays the sub-projects of root project 'hello-world'. properties - Displays the properties of root project 'hello-world'. tasks - Displays the tasks runnable from root project 'hello-world'. Other tasks ----------- helloWorld To see all tasks and more detail, run gradle tasks --all To see more detail about a task, run gradle help --task <task> BUILD SUCCESSFUL Total time: 2.028 secs This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.12/userguide/gradle_daemon.html
We see the output of both tasks. First, helloWorld
is executed, followed by tasks
. In the output, we see the task names prepended with a colon (:
) and the output is in the next lines.
Gradle executes the tasks in the same order as they are defined in the command line. Gradle will only execute a task once during the build. So even if we define the same task multiple times, it will only be executed once. This rule also applies when tasks have dependencies on other tasks. Gradle will optimize the task execution for us and we don't have to worry about that.