I would like to have in animalSniffer plugin one task 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 sourceSets (possibly separate test
and integrationTest
).
I wouldn't like to depend on *classes
tasks as *classes
tasks should depend animalSniffer
tasks (which detects Java version API incompatibilities after the compilation and can stop the build).
Is there a better way in Gradle to achieve that than checking if an instance of AbstractCompile
task name starts with "compileTest"?
The following code snippet is to define the external dependency. Use this code in build. gradle file. dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' } An external dependency is declaring the external dependencies and the shortcut form looks like "group: name: version".
To get an overview of all Gradle tasks in our project, we need to run the tasks task. Since Gradle 5.1, we can use the --group option followed by a group name. Gradle will then show all tasks belonging to the group and not the other tasks in the project.
You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.
Gradle allows you to define one or more default tasks that are executed if no other tasks are specified. defaultTasks 'clean', 'run' tasks. register('clean') { doLast { println 'Default Cleaning! ' } } tasks.
You can use tasks.withType(AbstractCompile)
which returns all compile tasks for all source sets (which includes Java, Groovy, Scala). You can then filter on this by eliminating all tasks that have test
in them as suggested in the other answer.
For a specific task to depend on all these, you can do the following:
myTask.dependsOn tasks.withType(AbstractCompile).matching {
!it.name.toLowerCase().contains("test")
}
If you need to differentiate between production and test compile tasks/source sets, checking whether the name contains test
(case-insensitive) is the best solution that's available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With