Executing multiple tasks

In this post of Gradle, I will show how to execute multiple tasks from command line.

Below is the gradle script with three tasks

build.gradle


task task1 {
    doFirst {
        println 'I am task1'
    }
}

task task2 {
    doFirst {
        println 'I am task2'
    }
}

task task3 {
    doFirst {
        println 'I am task3'
    }
}

Open the command line and go to the folder containing the build.gradle.

Run the below code

gradle task1 task2 task3

We are passing name of three tasks as argument to the command gradle.

The gradle build will search for build.gradle file in the current folder and execute the mentioned tasks in the order they are listed in the argument.

It will also execute dependent tasks. If multiple tasks say task2 and task3 depend on same task say task1, the dependent task task1 will be executed once.

Output

E:\Projects\GradleConcepts\package3>gradle task1 task2 task3

Task :task1
I am task1

Task :task2
I am task2

Task :task3
I am task3

BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s