I’d use this, which is slightly different:
configurations {
testArtifacts.extendsFrom testRuntime
}
task testJar(type: Jar) {
classifier "test"
from sourceSets.test.output
}
artifacts {
testArtifacts testJar
}
Without ‘testArtifacts.extendsFrom testRuntime’ you won’t get the dependencies of the tests if there are any.
Neither IDEA or Eclipse have the concept of a dependency on tests of a module. Luckily, module dependencies include visibility to any test source defined in that module. Both of the Gradle IDE plugins, will interpret the above code as a plain module dependency (i.e. just like ‘project(":some-project")’) which is pretty much what you want.
You have to be careful about dependency cycles though. You can easily have a situation where you do not have a cycle in the Gradle build, but due to the decreased granularity in the IDE you do have a cycle.