I have a large multiproject build. Each of our projects has tests in the following structure: tests/common tests/unit tests/functional
Classes in both tests/unit and tests/functional should have access to tests/common but shouldn’t be able to see each other. I have the following in my build.gradle:
sourceSets {
test {
java.srcDirs = ['test/unit']
}
testCommon {
java.srcDir 'test/common'
}
functionalTest {
java.srcDir 'test/functional'
}
}
dependencies {
testCommonCompile configurations.compile
testCompile configurations.testCommonCompile
functionalTestCompile configurations.testCommonCompile
testCommonCompile sourceSets.main.output
testCompile sourceSets.testCommon.output
functionalTestCompile sourceSets.testCommon.output
}
This works, but I’m assuming I’m declaring my inter-sourceset dependencies wrong, because it introduces a problem: when I use the Eclipse task, every project ends up depending on its own build/classes/testCommon.
For now, to get around that, I check to see if “eclipse” is present in the list of tasks, and if it is, I don’t declare the dependencies. What’s the right way to do this?