# \`gradle eclipse\` generates duplicate classpathentry in Eclipse's \`.classpath\` with gradle \>= 2.6

**URL:** https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784
**Category:** Bugs
**Created:** [September 21, 2015, 9:31pm UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784 "2015-09-21T21:31:34Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)
#### Post date: [September 21, 2015, 9:31pm UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/1 "2015-09-21T21:31:34Z")

</div>

The eclipse target generates duplicate `<classpathentry/>` entries in `.classpath` when run with gradle 2.6 or higher. See for example the xpp3 classpathentry in the following:

```
<classpath>
    <classpathentry kind="output" path="bin"/>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/resources"/>
    <classpathentry kind="src" path="src/test/java"/>
    <classpathentry kind="src" path="src/test/resources"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry sourcepath="/home/flo/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c-sources.jar" kind="lib" path="/home/flo/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar">
        <attributes>
            <attribute name="javadoc_location" value="jar:file:/home/flo/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c-javadoc.jar!/"/>
        </attributes>
    </classpathentry>
...
    <classpathentry kind="lib" path="/home/flo/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar"/>
...
</classpath>

```

([full file here](https://paste.debian.net/312796/))

This results in eclipse reporting “Build path contains duplicate entry … for project …”.

Happens with gradle 2.6 and 2.7. Does not happen with gradle 2.4. Not sure if this qualifies as regression (e.g. GRADLE-1953). The project in question is [https://github.com/igniterealtime/Smack](https://github.com/igniterealtime/Smack)

---

<div class="post-metadata">

### Author: ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)
#### Post date: [October 21, 2015, 10:51am UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/2 "2015-10-21T10:51:06Z")

</div>

The issue still exists in Gradle 2.8 btw.

---

<div class="post-metadata">

### Author: ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)
#### Post date: [January 24, 2016, 10:29am UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/3 "2016-01-24T10:29:55Z")

</div>

And it’s still here in 2.11rc1. ☹

---

<div class="post-metadata">

### Author: ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)
#### Post date: [February 9, 2016, 9:11am UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/4 "2016-02-09T09:11:05Z")

</div>

Gradle 2.11 still produces duplicate `.classpath` entries.

Looking at the `git log REL_2.4..REL_2.6` for the supposed relevant path `subprojects/ide/src/main` the commit series consisting of

- c3bb8f01c5bed7d653685ff517303cc8b8d3e9d4
- 3d8ec0df6364c2033a57efaf48abcca3578518d5
- a490fe506efa1aaf3bbeef9e73767e970fcb75e0
- 109bb0bc54def466a45ce413609c6215cbcb64b8
- 9b3b88f02392135f6828929bc30c51529fb9ae7c
- 612e8dae4864a9ad98e69ce98eb0e5a7746a6403  
could be the cause.

---

<div class="post-metadata">

### Author: ![lhotari](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lhotari/32/5552_2.png) [@lhotari](https://discuss.gradle.org/u/lhotari)
#### Post date: [February 9, 2016, 3:12pm UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/5 "2016-02-09T15:12:02Z")

</div>

Thanks for the bug report. I took a look at this and I was able to reproduce the problem and I can see the duplicate in `smack-tcp/.classpath`.

This might be a bug in version handling since when I change the xpp3 library dependency to `'xpp3:xpp3:1.1.3.3'` in `smack-core/build.gradle`, no duplicate gets produced in the `.classpath` files.

What catched my eye was the letter in the version of xpp3 dependency `'xpp3:xpp3:1.1.4c'`.  
I assume that the xpp3 dependency is the only duplicate and it could be related to a bug in version handling in Gradle.

I created a failing unit test [https://gist.github.com/lhotari/735a4ff4988d6820eac9#file-eclipseclasspathintegrationtest-groovy-L1061-L1101](https://gist.github.com/lhotari/735a4ff4988d6820eac9#file-eclipseclasspathintegrationtest-groovy-L1061-L1101) . The test passes with version ‘1.1.3.3’ .

The problem seems to occur with the dependency `testCompile project(':smack-core').sourceSets.test.runtimeClasspath`. Perhaps you could find a way to workaround the problem until this bug is fixed.

I have created the issue [https://issues.gradle.org/browse/GRADLE-3396](https://issues.gradle.org/browse/GRADLE-3396) to track this bug.

---

<div class="post-metadata">

### Author: ![lhotari](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lhotari/32/5552_2.png) [@lhotari](https://discuss.gradle.org/u/lhotari)
#### Post date: [February 9, 2016, 3:52pm UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/6 "2016-02-09T15:52:51Z")

</div>

The problem goes away when the dependencies are configured in a proper way.

Currently there are dependencies like this:  
`testCompile project(':smack-core').sourceSets.test.runtimeClasspath`

The correct way to express the dependency is:  
`testCompile project(path: ":smack-core", configuration: "testRuntime")`

---

<div class="post-metadata">

### Author: ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)
#### Post date: [February 10, 2016, 8:09am UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/7 "2016-02-10T08:09:10Z")

</div>

Thanks so much for your help. Really appreciated.

While this fixes the issue, it causes `gradle check` to fail with

```
:smack-experimental:compileTestJava
/home/flo/data/code/smack/smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java:21: error: package org.jivesoftware.smack.test.util does not exist
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
                                              ^
/home/flo/data/code/smack/smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java:21: error: static import only from classes and interfaces
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
^
2 errors
:smack-experimental:compileTestJava FAILED

```

So the code from `smack-core/src/test/java` is not available to smack-experimental test runtime. I believe that is why I added the dependency this way in the first place.

How can I fix this too?

---

<div class="post-metadata">

### Author: ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)
#### Post date: [February 10, 2016, 11:31am UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/8 "2016-02-10T11:31:02Z")

</div>

I think i’ve fixed it by adding the "archives’ configuration, which includes the test jar.

```
dependencies {
	compile project(':smack-core')
	testCompile project(path: ":smack-core", configuration: "testRuntime")
	testCompile project(path: ":smack-core", configuration: "archives")
}

```

Thanks to [https://softnoise.wordpress.com/2014/09/07/gradle-sub-project-test-dependencies-in-multi-project-builds/](https://softnoise.wordpress.com/2014/09/07/gradle-sub-project-test-dependencies-in-multi-project-builds/) for the hint.

---

<div class="post-metadata">

### Author: ![lhotari](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lhotari/32/5552_2.png) [@lhotari](https://discuss.gradle.org/u/lhotari)
#### Post date: [February 10, 2016, 1:38pm UTC](https://discuss.gradle.org/t/gradle-eclipse-generates-duplicate-classpathentry-in-eclipses-classpath-with-gradle-2-6/11784/9 "2016-02-10T13:38:53Z")

</div>

Looks good to me. Kudos to @hauner for the helpful article.
