Gradle : How to run a specific gradle task or multiple tasks

How to run a specific gradle task

When you want to run a particular task only then you can run that task using the following command.

gradle -q <task-name>

-q option tells gradle that you want to run only the tasks that are provided. In this example we have instructed gradle to run only one task

How to run multiple gradle tasks

Multilple gradle tasks can be run using the following syntax.

gradle -q <task-name> <task-name> <task-name>

In second example we have told gradle to run 3 tasks, they are run in the order they are provided. However if one of the task is dependent on any other task, then that task will execute first. Also A task is run only one time even if it is specified multiple times.

For example if we have the following tasks in build.gradle

task A {
    doLast {
        println 'Running task A'

        println(" Pring first")

task B(dependsOn: A) {
    doLast {
        println 'Running task B'

task C(dependsOn: [A, B]) {
    doLast {
        println 'Running task C'

and we run the tasks using the following command.

gradle B A C

Then the gradle tasks will be executed in this manner First A will execute then B and finally C will execute.


No comments :

Post a Comment