Gradle with Eclipse - incomplete .classpath when multiple sources

I have a gradle build script with several sets of sources that have different dependencies (some common, some not) and I'm trying to use the Eclipse plugin to gradle generate .project and .classpath for Eclipse, but I can’t figure out how to get everything dependency records in .classpath ; for some reason, quite a few external dependencies are actually added to .classpath , and as a result, the Eclipse build failed with 1400 errors (creating with gradle works fine).

I defined my source sets as follows:

 sourceSets { setOne setTwo { compileClasspath += setOne.runtimeClasspath } test { compileClasspath += setOne.runtimeClasspath compileClasspath += setTwo.runtimeClasspath } } dependencies { setOne 'external:dependency:1.0' setTwo 'other:dependency:2.0' } 

Since I am not using the original set of main , I thought this might have something to do with it, so I added

 sourceSets.each { ss -> sourceSets.main { compileClasspath += ss.runtimeClasspath } } 

but it did not help.

I was not able to figure out any general properties of the libraries that are included, or those that are not, but I can not find anything that I am sure of (although, of course, there should be something). I feel that all of the included libraries are dependencies of the original test suite, directly or indirectly, but I could not verify that more than that all the test dependencies exist.

How can I guarantee that dependencies of all source sets are placed in .classpath ?

+7
source share
3 answers

This was resolved in a way that was closely related to a similar question that I asked yesterday:

 // Create a list of all the configuration names for my source sets def ssConfigNames = sourceSets.findAll { ss -> ss.name != "main" }.collect { ss -> "${ss.name}Compile".toString() } // Find configurations matching those of my source sets configurations.findAll { conf -> "${conf.name}".toString() in ssConfigNames }.each { conf -> // Add matching configurations to Eclipse classpath eclipse.classpath { plusConfigurations += conf } } 

Update:

I also asked the same question on the Gradle forums and got an even better solution:

 eclipseClasspath.plusConfigurations = configurations.findAll { it.name.endsWith("Runtime") } 

This is not so accurate, because it adds other things besides the things from my source sets, but guarantees that it will work. And it is much easier on the eyes =)

+2
source

I agree with Thomas Liken, it is better to use the second option, but a small correction may be required:

eclipse.classpath.plusConfigurations = configurations.findAll {it.name.endsWith ("Runtime")}

+2
source

This is what worked for me with Gradle 2.2.1:

 eclipse.classpath.plusConfigurations = [configurations.compile] 
+1
source

All Articles