# Multiprojects: wrong test classpath

**URL:** https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648
**Category:** Buildship
**Tags:** issue-resolved
**Created:** [November 6, 2015, 9:02am UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648 "2015-11-06T09:02:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Alex2](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Alex2](https://discuss.gradle.org/u/Alex2)
#### Post date: [November 6, 2015, 9:02am UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/1 "2015-11-06T09:02:56Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)
#### Post date: [November 6, 2015, 12:41pm UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/2 "2015-11-06T12:41:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Alex2](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Alex2](https://discuss.gradle.org/u/Alex2)
#### Post date: [November 6, 2015, 2:13pm UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/3 "2015-11-06T14:13:13Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)
#### Post date: [November 10, 2015, 9:48am UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/4 "2015-11-10T09:48:52Z")

</div>

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](https://bugs.eclipse.org/bugs/show_bug.cgi?id=481816)

---

<div class="post-metadata">

### Author: ![Kris\_De\_Volder1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kris_de_volder1/32/408_2.png) [@Kris\_De\_Volder1](https://discuss.gradle.org/u/Kris_De_Volder1)
#### Post date: [November 16, 2015, 5:56pm UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/5 "2015-11-16T17:56:26Z")

</div>

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](https://bugs.eclipse.org/bugs/show_bug.cgi?id=482315)

---

<div class="post-metadata">

### Author: ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)
#### Post date: [November 20, 2015, 9:04am UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/6 "2015-11-20T09:04:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)
#### Post date: [July 26, 2016, 2:43pm UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/7 "2016-07-26T14:43:46Z")

</div>

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](http://download.eclipse.org/buildship/updates/e46/snapshots/1.0).

---

<div class="post-metadata">

### Author: ![nishantghan](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@nishantghan](https://discuss.gradle.org/u/nishantghan)
#### Post date: [March 5, 2019, 10:09pm UTC](https://discuss.gradle.org/t/multiprojects-wrong-test-classpath/12648/8 "2019-03-05T22:09:24Z")

</div>

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.
