How to prevent gradle creation from running a test task

I know that I can use the -x test option to prevent the calling task from being called. I also have something like this in my gradle script to prevent tests from running 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 remove the dependency between build-> test?

+5
gradle
source share
3 answers

assembly depends on test through verification. You probably don't want to remove the dependency from the validation, as it can do other things, so you can try:

check.dependsOn.remove(test)

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

+10
source share

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

 ./gradlew assembleDebug -x taskToSkip 
+3
source share

I do not know if such a dependency can be removed. However, you can skip the execution of tasks, for example: skip all test tasks (during production), like this.

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

All Articles