Buildship removes all library references from .classpath?

Hello,

I’m trying to add some custom libraries to .classpath (.jars to aspectpath, actually) and I’d like Gradle/Buildship to generate everything automatically. I figured several ways of achieving this, all of them worked correctly with ‘plain’ Gradle calls (gradlew eclipse…) but it seems Buildship is also executing my code but removing the extra libraries at the end. The scenario I’d like to have is that I import an exising Gradle project (having no Eclipse files at all) - it would be nice to import projects from different version controls…

First I tried to add the jars using eclipse.classpath.file.withXml but I realized it’s not processed by Buildship. Then I figured that this can be done also with eclipse.classpath.file.whenMerged. According to my debug it’s invoked even if there’s no initial .classpath file, but at the end of the import all my libs disappear.

            whenMerged { classpath ->
                configurations.aspectpath.files.each { file ->
                    def lib = new org.gradle.plugins.ide.eclipse.model.Library(fileReference(file))
                    lib.entryAttributes.put("org.eclipse.ajdt.aspectpath", "org.eclipse.ajdt.aspectpath")
                    entries += lib
                }

The third way I tried is to have an initial .classpath file containing only the jar references for aspectpath and rely on classpath merging. Unfortunately the output is the same, my aspectpath entries just disappear.

What am I doing wrong?

Tried all this with Buildship 2.0.0 and 2.0.2, with Gradle 3.3 and 3.5.

Zsolt G.

Btw, is there a chance to have something like this with Buildship (i.e. have multiple Gradle classpath containers on .classpath referring to different configurations)?

This should work just fine. Using whenMerged {} is the way to go for any modifications to the Eclipse classpath. Can you provide a reproducible example where ti doesn’t?

Unfortunately I cannot upload any content as I’m a new user here, but I managed to reproduce the issue with just a single build.gradle file in a folder + the referenced jar:

my-project
±- build.gradle
±- lib/spring-aspects-3.2.15.RELEASE.jar

build.gradle:

apply plugin: ‘java’
apply plugin: ‘eclipse-wtp’

eclipse.classpath {

containers 'org.eclipse.ajdt.core.ASPECTJRT_CONTAINER'
file.whenMerged { classpath ->
                def lib = new org.gradle.plugins.ide.eclipse.model.Library(fileReference(file('lib/spring-aspects-3.2.15.RELEASE.jar')))
                lib.entryAttributes.put("org.eclipse.ajdt.aspectpath", "org.eclipse.ajdt.aspectpath")
                entries += lib
}

}

.classpath file generated with command line call and Buildship import differs only at one point, the command-line-generated one contains the aspectpath entry as I expected, but it’s missing in the Buildship-generated file which has the ‘gradleclasspathcontainer’ instead.

I’m using
Eclipse Java EE IDE for Web Developers.
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600

The Gradle classpath container should contain your manually added library. If it doesn’t, please create a small project on GitHub that shows the issue.

Well, yes, Gradle classpath container do contain everything… I was just focusing on .classpath file and haven’t checked other project propeties and settings as I was not satisfied with .classpath. I did not assume that the container is capable of providing more than project.dependencies… Is there a description about the features and capabilities of Gradle Classpath Container?

Thanks for the help!