Skip a task while performing another task

I added a task to the gradle project:

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

Now the build task is always executed before the deploy task. This is great because the build task involves many steps. Now I want to explicitly disable one of these included tasks.

I usually disconnect it from the command line using

 gradle deploy -x test 

How can I exclude the test task programmatically?

+5
source share
2 answers

You need to configure the task schedule, not configure the deploy task. Here is the code snippet you need:

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

I do not know what your deployment task does, but it probably just should not depend on the build task. The build task is a very complex life cycle task that includes a ton of things that you probably don't need.

Instead, it should correctly identify its inputs (perhaps the artifacts you want to deploy), and then Gradle will only perform the necessary tasks to create these inputs. Then you no longer need any exceptions.

+1
source

Source: https://habr.com/ru/post/1259884/


All Articles