Incomplete Eclipse Classpath when using custom sourceSet(?)


(Mike Meessen) #1

Hi there,

I stumbled upon an issue while generating the eclipse ‘.classpath’ file.

Using Gradle 1.6, and given the following minimalistic buildfile:

apply plugin: 'java'
apply plugin: 'eclipse'
  repositories {
    mavenCentral()
}
  sourceSets {
    intTest
}
  dependencies {
    testCompile (group: 'jmock', name: 'jmock-cglib', version: '1.1.0')
    intTestCompile (group: 'commons-io', name: 'commons-io', version: '2.4')
}
  task echoEclipseSourceSets() << {
    eclipse.classpath.sourceSets.each { println it }
}

… why doesn’t ‘commons-io’ end up in the eclipse classpath? Since the eclipse plugin picks up all sourceSets when generating eclipse source directories, shouldn’t it also pick up all dependencies of those sourceSets?

… or am I missing something?

Interestingly, ‘eclipse.classpath.sourceSets’ seems to know about the intTest sourceSet: The ‘echoEclipseSourceSets’ yields:

$ gradle echoEclipseSourceSets
:echoEclipseSourceSets
source set 'int test'
source set 'main'
source set 'test'

Thanks in advance, Mike


(Joel Robotham) #2

Hi Mike, I think you just need to add something like:

eclipse {
        classpath {
            plusConfigurations += configurations.intTestCompile
        }
    }

(Mike Meessen) #3

Ah, nice, thx for the hint, joel :slight_smile: I wasn’t aware that a sourceSet implicitly creates configurations like this :wink:

Nevertheless, @gradle staff: shouldn’t gradle do that automatically, since it also includes the sourceset’s source folders in eclipse automatically? Putting a sourceset’s source files in an eclipse project, without the corresponding dependencies will always create projects with compile errors by default… which seems like a bad behavior :wink:


(Joel Robotham) #4

Plus you’d need to add the same in to the idea configuration if you’re using IntelliJ as well…