Exclusion of transitive dependencies

I have a multi build gradle setup with the following dependency structure:

+--- moduleA
+--- org.springframework:spring-beans:3.1.4.RELEASE
|    \--- org.springframework:spring-core:3.1.4.RELEASE
|         +--- org.springframework:spring-asm:3.1.4.RELEASE
|         \--- commons-logging:commons-logging:1.1.1
\--- project :moduleB

\--- moduleB
\--- org.springframework:spring-beans:1.2.8
     +--- org.springframework:spring-core:1.2.8
     |    +--- commons-logging:commons-logging:1.0.4
     |    \--- commons-collections:commons-collections:3.1
     \--- commons-logging:commons-logging:1.0.4

Basically moduleA depends on Spring 3 meanwhile moduleB depends on Spring 1.2.8.
Also moduleA depends on module B and excludes the dependency org.springframework (which is transitive for moduleB).

The gradle configuration for moduleA is:

dependencies {
    compile "org.springframework:spring-beans:3.1.4.RELEASE"
    compile (project(":moduleB")) {
        exclude group: "org.springframework"

The gradle configuration for moduleB is:

dependencies {
    compile "org.springframework:spring-beans:1.2.8"

Using the gradle command line for displaying the dependencies I can confirm that Spring 1.2.8 is being excluded correctly from the point of view of moduleA.
Now when working from Eclipse this does not happen. The moduleA is using in fact classes from Spring 1.2.8 which it causes compile issues.

Is this a known limitation of the plugin?


I am using Gradle 2.4 and I have just intalled the Buildship plugin from the Marketplace.

The classpath mapping changed in Gradle 2.5 to deal with this kind of issue. Can you try with Gradle 2.5?

@adammurdoch I have just tried with Gradle 2.5 and the importing of the projects took more time, but the outcome is the same, dependency exclusions are not being honoured. I could replicate this in a project from scratch and upload it here if it helps.

Thanks, Jonathan. A self-contained sample would be awesome and make it quicker for us to analyze the issue.

@etiennestuder I have attached to this post a sample of this issue.
As you can see, after importing the multi-project into Eclipse, the moduleA will contain compile errors because it’s using Spring 1.2.8 classes instead of 3.0.0, even though it’s excluded.

Thanks for your time

gradleIssue.zip (52.3 KB)

We will look into this shortly. I created a ticket in Bugzilla for this issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=473348.

I cannot reproduce your problem with the zip you provided. when using the buildship import feature. All dependencies are resolved as expected:

are you sure you have tested this with gradle 2.5?

@Rene Yes, I am using Gradle 2.5:

And Eclipse:

If you need me to try something, let me know, I am happy to help!

I noticed I was using Java 6 with Gradle, I switched to Java 8, just for testing, but the same problem.

I do not see a difference between the screenshots provided by @Rene and @jonathannaguin in terms of dependency versions. Both screenshots also look like the cmd line output shown by Jonathan. Have I missed something?

Also, please note that you need to remove the generated .project files before re-importing, otherwise Buildship does not touch the existing projects (that is intended behavior).

@etiennestuder Yup, I remembered to delete first the .project files before the import.
The different is that I am getting a compile error in ApplicattionA.java because it is not using actually Spring 3, but Spring 1. The screenshot provided by @Rene seems to suggests that he does not have such compile error (unless he had disabled the auto-build setting).

@jonathannaguin: Do you get this even after ‘Project…’ -> Clean?
@Rene: Can you verify (if not done already) that the libs used in project A are actually Spring 3?

Hm, so two people are importing the exact same project (the one attached by Jonathan), and one Eclipse is fine with it while the other is not. @donat please also import this project from the .zip and let us know the outcome.

@etiennestuder I’ve just tried to clean up all the projects… Sorry, the same… I have also tried to refresh every project several times, and does not help.

And you select ‘Gradle Wrapper’ in the Distribution Tab of the Import Wizard?

@etiennestuder Yup, Gradle Wrapper and no other options. In the next screen, I can confirm that it is using 2.5. Let me know if you need more info from me! :smile:

@Rene @etiennestuder I have just noticed that in the Eclipse screenshot that Rene posted the moduleA does not have moduleB as a dependency, or at least it is not listed like in my Eclipse.

good catch. But moduleB is definitely configured as a dependency. also you’re seeing your dependencies summed up in “Project & External Dependencies”. Where does this come from?

@Rene That was created automatically by the plugin… Looking at the code in Github I found this reference to this container: “ClasspathContainer_Label” under CoreMessages.

We could successfully reproduce the issue. This issue is our top priority to fix for Buildship 1.0.2.

@donat Thank you! I really appreciate it.