Skip a task when running another task

I don't know what your deploy task does, but it probably just shouldn't depend on the 'build' task. The 'build' task is a very coarse grained lifecycle task that includes tons of stuff you probably don't want.

Instead it should correctly define its inputs (probably the artifacts that you wanna deploy) and then Gradle will only run the necessary tasks to build those inputs. Then you no longer need any excludes.


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

Tags:

Skip

Gradle