Gradle: testDependents and testNeeded

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?

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
 }
}

Thanks, works like a charm :slight_smile: