How to depend on all * compilation and * testCompile tasks in Gradle

I would like to have one task plugin in animalSniffer to depend on compilation of all production classes (Java, Groovy, Scala) in all sourceSets and the second to depend on compilation of all test classes in all source sets (it is possible to separate test and integrationTest ).

I would not want to depend on *classes tasks, since *classes tasks should depend on animalSniffer tasks (which are incompatible with the Java version of the API after compilation and may stop the build).

Is there a better way in Gradle to achieve this than checking if an instance of the AbstractCompile task name is started with "compileTest"?

+5
source share
2 answers

You can use tasks.withType(AbstractCompile) , which returns all compiled tasks for all source sets (including Java, Groovy, Scala). You can then filter this out by excluding all tasks with test in them, as suggested in another answer.

For a specific task that depends on all of this, you can do the following:

 myTask.dependsOn tasks.withType(AbstractCompile).matching { !it.name.toLowerCase().contains("test") } 
+2
source

If you need to distinguish between production and test compilation tasks / source sets, checking if the name test (case insensitive) is the best solution available.

+1
source

Source: https://habr.com/ru/post/1208091/


All Articles