Complex SourceSet Dependencies and Eclipse projects

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?

Are you sure declaring the dependencies conditionally solves the problem? Eclipse has a single classpath per project. So assuming that all source sets are a part of a single Eclipse project, classes can depend on any class from any sourceset.

Yes, it does solve the problem:

With unconditional dependencies:

$ grep testCommon .classpath
  <classpathentry kind="lib" path="<snip>/trunk/Base/build/classes/testCommon" exported="true"/>
 <classpathentry kind="lib" path="<snip>/trunk/Base/build/resources/testCommon" exported="true"/>

With conditional dependencies:

$ grep testCommon .classpath