How to prevent gradle build from executing test ta

2019-04-29 16:40发布

问题:

I know that I can use the -x test option to prevent the test task from getting called. I also have something like this in my gradle script to prevent tests from being executed in certain cases:

plugins.withType(JavaPlugin).whenPluginAdded {
    test {
        doFirst {
            if (env.equals('prod')) {
                throw new StopExecutionException("DON'T RUN TESTS IN PROD!!!!")
            }
        }
    }
}

but is there a way to configure the java plugin to removed the dependency between build -> test?

回答1:

build depends on test via check. You probably don't want to remove the dependency on check as it may do other things, so you could try:

check.dependsOn.remove(test)

Do you mind if I ask why you want to do this?



回答2:

You can skip tasks via the command line with the -x option:

./gradlew assembleDebug -x taskToSkip


回答3:

I don't know if it is possible to remove such a dependency. You can however skip the execution of tasks, eg: skipping all test tasks (in production) goes like this.

tasks.withType(Test).each { task ->
    task.enabled = !env.equals('prod')
}


标签: gradle