Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude tasks from the task that my task depends on

Tags:

gradle

I created task which depends on build.

task packageJar(dependsOn: build, type: JavaExec) {
    main = 'com.xxxx.util.KiePackageCreator'
    classpath = sourceSets.main.runtimeClasspath
}

But build task invokes other tasks like checkstyle, test and etc. How to exclude them?

I can do it through console -x but how to do it inside task?

like image 609
lapots Avatar asked Nov 25 '15 06:11

lapots


1 Answers

You can simply disable the tasks, by setting it's enabled property to false in the root of the script:

test.enabled = false

But in that case, those tasks won't ever run. If you just need them to not running if some other task is called, then you have to use execution graph:

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

But not sure at the moment, whether it is possible to change this property when the graph is ready. If not, then you can make a variable and in the tasks, you want to exclude, add the doFirst block, which will throw the StopExecutionException according to this variable value.

like image 55
Stanislav Avatar answered Oct 23 '22 09:10

Stanislav