Multiprojects: wrong test classpath

In a gradle multi-project configuration, when a project depends on several others who share different versions of same dependencies, all those versions are present in the classpath when running a test in eclipse (4.5.1 with buildship 1.0.5).

eg. in the following multiproject

project
 |-- project1
 |    |-- log4j 1.2.14
 |-- project2
 |    |-- log4j 1.2.17
 |-- project-tests
 |    |-- project(':project1')  
 |    |-- project(':project2')  

Then when running a test in eclipse, test classpath in project-tests project will include both log4j-1.2.14 and log4j-1.2.17. Obviously it leads to runtime issues dependending on which version comes first in classpath.

While when running tests with gradle test, only the younger version will show up (as I would expect).

A self-contained example using gradle-2.8 is available on https://github.com/Starch/idea_wrong_classpath (problem appears also on idea, hence the project name). Just launch ClasspathTest in project-tests.

Note that the classpath in project properties seems correct (project1 and project2 do not export their deps and project-tests have only log4j-1.2.17). But when I run a test both log4j versions are in classpath.

What is the version of Gradle that you run the build with?
Note that as of Gradle 2.5, the generated classpath is not using any exports anymore.

Etienne

I use gradle-2.8.

Indeed, gradle 2.5 fixes some classpath problems that made eclipse unable to compile code in some cases (because it would have used the version exported by a module instead of its own).

But here the problem occurs only when running tests, where several versions of the same modules come into the classpath. Although as I said, the dependencies seems to be correct in project properties:

  • log4j-1.2.17 in project-tests dependencies
  • no exported dep in project1 and project2

I just found out what causes the problem. Buildship defines project dependencies inside the classpath container. Turns out if a project dependency is specified inside a classpath container then the isExported flag is ignored for runtime.

I’ve created a Bugzilla issue to follow-up on this problem : https://bugs.eclipse.org/bugs/show_bug.cgi?id=481816

There is also a similar problem with non-multi-projects. I’ve put in bugreport for it here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482315

Thanks for the bug report. I’ll follow-up on the Bugzilla issue.

The fix for this issue has been implemented and soon will be released as part of Buildship 1.0.18. You can test it with latest development snapshot.

I have the latest version of Buildship Eclipse Plugin installed but I amd still facing the same issue. Junit-4.10 gets precedence over 4.12 and causes compiler error.