gradle custom task that depends on build task without testing

醉酒当歌 提交于 2020-03-04 23:19:30

问题


I am using gradle 6.0.1

I am trying to write my on task, but I want first the the build task is executed but without tests.

I tried (from build.gradle):

task startEnv(type: GradleBuild) {
    tasks = ['build']
    doLast {
        // START ENV CODE
    }
}

However, I don't manage to find a way to call build without running tests, as I would run

gradle build -x test

Is it possible to achieve this functionality?

Another option I can use, is to check inside my startEnv task whether build already exists and run this task only if build exists - Is there a way to query whether build exists? (this is a multi module projects, so I am not sure it is enough to check whether build directory exists on the root project).

I followed the comments and tried the solution mentioned at Skip a task when running another task

I added to build.gradle:

gradle.taskGraph.whenReady { graph ->
    if (graph.hasTask(startEnv)) {
        println("DEBUG1")
        test.enabled = false
    }
}

task startEnv(type: GradleBuild) {
    tasks = ['build']
    doLast {
       // START ENV CODE
    }
}

But when I run ./gradlew startEnv - it still fails with some tests that in current phase I know they should fail. I can see the DEBUG1 print when I execute this command but the build fails with tests that are failing.

Thank you,

来源:https://stackoverflow.com/questions/60460651/gradle-custom-task-that-depends-on-build-task-without-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!