Is there a clean way to run all test task for project Java dependencies in Gradle ? I noticed that Java dependencies only get their "jar" task run, and skip test / build.
main-code build.gradle
dependencies {
compile project(":shared-code")
}
gradle :main-code:build <-- Command that I want to run (that will also run :shared-code:tests , don't want to explicitly state it)
:shared-code:compileJava UP-TO-DATE
:shared-code:processResources UP-TO-DATE
:shared-code:classes
:shared-code:jar
<-- what actually gets run for shared-code (not missing build/tests)
** Best thing I can think of is a finalizeBy task on jar with test
Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.
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.
By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.
UPD: Actually there is a task called buildNeeded
buildNeeded - Assembles and tests this project and all projects it depends on.
It will build an run tests of the projects your current project is dependent on.
OLD ANSWER:
Seems that gradle doesn`t do it out-of-box (tested on version 2.14.1). I came up with a workaround. build task triggers evaluation of a chain of other tasks which include testing phase.
testwebserver/lib$ gradle build --daemon
:testwebserver-lib:compileJava UP-TO-DATE
:testwebserver-lib:processResources UP-TO-DATE
:testwebserver-lib:classes UP-TO-DATE
:testwebserver-lib:jar UP-TO-DATE
:testwebserver-lib:assemble UP-TO-DATE
:testwebserver-lib:compileTestJava UP-TO-DATE
:testwebserver-lib:processTestResources UP-TO-DATE
:testwebserver-lib:testClasses UP-TO-DATE
:testwebserver-lib:test UP-TO-DATE
:testwebserver-lib:check UP-TO-DATE
:testwebserver-lib:build UP-TO-DATE
In order to force testing of dependency project (testwebserver-lib) for a dependent project (testwebserver) I added a task dependency in testwebserver/build.gradle:
...
compileJava.dependsOn ':testwebserver-lib:test'
dependencies {
compile project(':testwebserver-lib')
}
...
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