vicsz
vicsz

Reputation: 9754

By default run gradle tests for project dependencies

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

Upvotes: 7

Views: 2066

Answers (1)

dnsglk
dnsglk

Reputation: 167

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

Upvotes: 5

Related Questions