To produce a jar containing test sources and use it elsewhere in a Gradle multi-module project (component A depends on component B):
Create a new configuration in component A:
// components/A/build.gradle
configurations {
test-helpers
}
Add a jar task with the source sets that configuration needs:
// components/A/build.gradle
task factoryJar(type: Jar) {
appendix = "test-helpers"
from sourceSets.test.output
from sourceSets.main.output
}
Declare that jar as an artifact for that configuration:
// components/A/build.gradle
artifacts {
test-helpers factoryJar
}
Declare a dependency on component A, specifying the factory
configuration
// components/B/build.gradle
testCompile project(path: ":components/A", configuration: 'test-helpers')