Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip a task when running another task

Tags:

gradle

skip

I added a task to my gradle project:

task deploy() {
    dependsOn "build"
    // excludeTask "test"  <-- something like this

    doFirst {
       // ...
    }
}

Now the build task always runs before the deploy task. This is fine because the build task has many steps included. Now I want to explicitly disable one of these included tasks.

Usually I disable it from command line with

gradle deploy -x test

How can I exclude the test task programmatically?

like image 259
Marcel Avatar asked Nov 17 '16 08:11

Marcel


1 Answers

You need to configure tasks graph rather than configure the deploy task itself. Here's the piece of code you need:

gradle.taskGraph.whenReady { graph ->
    if (graph.hasTask(deploy)) {
        test.enabled = false
    }
}

WARNING: this will skip the actions defined by the test task, it will NOT skip tasks that test depends on. Thus this is not the same behavior as passing -x test on the command line

like image 126
Opal Avatar answered Sep 29 '22 11:09

Opal