In my root build.gradle, i have defined this:
configurations {
testArtifacts
}
task testJar (type: Jar) {
baseName = "${project.name}-test"
from sourceSets.test.output
}
artifacts {
testArtifacts testJar
}
Then in the project that needs the test code i declare it as a normal dependency:
testCompile project (path: ":some-project", configuration: 'testArtifacts')
This works fine for eclipse tests and command-line gradle test at least. Can’t say i have tried for intelliJ