Gradle: testDependents and testNeeded


(Christian Bremer) #1

With the gradle java plugin you get the following tasks which are very neat:

buildDependents buildNeeded

I would like to have similar tasks for running tests only.

testDependents - runs the unit tests for this project and all projects that depend on it. testNeeded - runs the unit tests for this and all projects it depends on.

Can I somehow create such custom tasks in gradle?


(René Groeschke) #2

Hello Christian, you should be able to add those tasks in your build script. this should work:

allprojects {
        apply plugin:'java'
 task testDependents{
  dependsOn (configurations.testRuntime.getTaskDependencyFromProjectDependency(false, "testDependents"))
  dependsOn test
 }
    task testNeeded{
  dependsOn (configurations.testRuntime.getTaskDependencyFromProjectDependency(true, "testNeeded"))
  dependsOn test
 }
}

(Christian Bremer) #3

Thanks, works like a charm :slight_smile: