How to prevent gradle build from executing test task

Viewed 14934

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?

3 Answers

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?

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')
}
Related