# Eclipse Plugin - Adding Classpath Entries Remove them Instead

**URL:** <https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447>\
**Category:** Old Forum Archive\
**Created:** [January 27, 2012, 6:22pm UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447 "2012-01-27T18:22:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 27, 2012, 6:22pm UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/1 "2012-01-27T18:22:00Z")

</div>

I am trying to make sure a classpath entry are present in the .classpath file. Even when I manually add them after running the gradle build the entries are removed.

```gradle
eclipse {
 project {
  name = 'IBLink'
      buildCommand 'org.eclipse.jdt.core.javabuilder'
      natures 'com.springsource.sts.gradle.core.nature', 'org.eclipse.jdt.groovy.core.groovyNature'
 }
 classpath {
  containers 'DROOLS/Drools', 'GROOVY_SUPPORT', 'GROOVY_DSL_SUPPORT', 'com.springsource.sts.gradle.classpathcontainer'
      file {
   withXml {
    def node = it.asNode()
    node.appendNode('classpathentry', [kind: 'src', path: '/GenericDataRoutingContext'])
    node.appendNode('classpathentry', [kind: 'src', path: '/GenericTradingInterface'])
    node.appendNode('classpathentry', [kind: 'src', path: '/Utils'])
    node.appendNode('classpathentry', [kind: 'src', path: 'ib'])
   }
  }
 }
    downloadSources = true
 downloadJavadoc = true
}

```

Manually added:

```gradle
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" path="src/main/java"/>
 <classpathentry kind="src" path="src/main/scala"/>
 <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 <classpathentry exported="true" kind="con" path="com.springsource.sts.gradle.classpathcontainer"/>
 <classpathentry combineaccessrules="false" kind="src" path="/ApacheParent"/>
 <classpathentry combineaccessrules="false" kind="src" path="/GenericDataRoutingContext"/>
 <classpathentry combineaccessrules="false" kind="src" path="/GenericTradingInterface"/>
 <classpathentry combineaccessrules="false" kind="src" path="/Utils"/>
 <classpathentry kind="output" path="target/classes"/>
</classpath>

```

After running gradle

```gradle
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" path="src/main/java"/>
 <classpathentry kind="src" path="src/main/scala"/>
 <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 <classpathentry exported="true" kind="con" path="com.springsource.sts.gradle.classpathcontainer"/>
 <classpathentry kind="output" path="target/classes"/>
</classpath>

```

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 27, 2012, 11:09pm UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/2 "2012-01-27T23:09:00Z")

</div>

I don’t understand. Given your ‘build.gradle’, everything you list under ‘manually added’ (except for ‘/ApacheParent’) should already be generated by ‘gradle eclipse’.

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 28, 2012, 5:54am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/3 "2012-01-28T05:54:00Z")

</div>

What I meant by manually added is I put in the entire through the project properties page in eclipse. What .classpath gradle generates do not have the entries for some reason.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 28, 2012, 6:40am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/4 "2012-01-28T06:40:00Z")

</div>

Your example is confusing. Why would you add an entry both with ‘node.appendNode’ and then again manually in the IDE?

As a general answer, the Eclipse plugin doesn’t keep 'classpathentry’s of kind ‘src’, ‘var’, and ‘con’. This is because it generates such entries itself and wouldn’t be able to tell if an encountered entry was previously generated by itself (and needs to be replaced) or added manually (and needs to be kept). Therefore it assumes the common and recommended case, namely that all dependency information is configured in Gradle. Going forward, the STS Gradle plugin may be in a better position to solve such use cases.

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 28, 2012, 6:49am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/5 "2012-01-28T06:49:00Z")

</div>

Shouldn’t

```gradle
node.appendNode('classpathentry', [kind: 'src', path: '/GenericDataRoutingContext'])
                node.appendNode('classpathentry', [kind: 'src', path: '/GenericTradingInterface'])
                node.appendNode('classpathentry', [kind: 'src', path: '/Utils'])
                node.appendNode('classpathentry', [kind: 'src', path: 'ib'])

```

Add

```gradle
<classpathentry combineaccessrules="false" kind="src" path="/GenericDataRoutingContext"/>
    <classpathentry combineaccessrules="false" kind="src" path="/GenericTradingInterface"/>
    <classpathentry combineaccessrules="false" kind="src" path="/Utils"/>
    <classpathentry combineaccessrules="false" kind="src" path="ib"/>

```

I use STS plugin.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 28, 2012, 6:52am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/6 "2012-01-28T06:52:00Z")

</div>

I’d expect it to add four entries (not six).

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 28, 2012, 6:59am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/7 "2012-01-28T06:59:00Z")

</div>

Sorry my bad.

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 28, 2012, 7:02am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/8 "2012-01-28T07:02:00Z")

</div>

I just want to know a fail proof way to add entries to the .classpath/.project files from Gradle.

I thought this might be the way but does not seam to work

```gradle
def node = it.asNode()
node.appendNode('classpathentry', [kind: 'src', path: '/GenericDataRoutingContext'])

```

I just need to know what the right syntax is to get this done, since I am new to gradle.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 28, 2012, 7:16am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/9 "2012-01-28T07:16:00Z")

</div>

Hmm, this looks fine to me. Which Gradle version?

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 28, 2012, 7:24am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/10 "2012-01-28T07:24:00Z")

</div>

1.0 RC7

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 28, 2012, 7:25am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/11 "2012-01-28T07:25:00Z")

</div>

Indeed this code works fine for me. I’ve tried with 1.0-milestone-7, but I would also expect this to work with earlier versions.

Maybe there is a misunderstanding here. This code will affect what goes into the ‘.classpath’ file, but that file isn’t used by the STS plugin. You can _either_ use the Gradle Eclipse plugin and then open the generated Eclipse project, _or_ use the STS plugin.

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [January 28, 2012, 7:28am UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/12 "2012-01-28T07:28:00Z")

</div>

I am using STS 2.8.1. I have set the container to 1.0-milestone-7.

---

<div class="post-metadata">

**Author:** ![kris\_de\_volder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kris_de_volder/32/514_2.png) [@kris\_de\_volder](https://discuss.gradle.org/u/kris_de_volder)\
**Post date:** [February 27, 2012, 4:55pm UTC](https://discuss.gradle.org/t/eclipse-plugin-adding-classpath-entries-remove-them-instead/7447/13 "2012-02-27T16:55:00Z")

</div>

One possible reason some source entries are going missing is if the corresponding source folders do not exist in your project.

Source entries for non-existent folders are ignored. Not sure this is the case here, but do make sure the folders exist before importing or refreshing source folders in STS.

> Maybe there is a misunderstanding here. This code will affect what goes into the .classpath file, but that file \> isn’t used by the STS plugin. You can either use the Gradle Eclipse plugin and then open the generated

> Eclipse project, or use the STS plugin.

Correction. This is not quite true. It would depend on how exactly a project got imported. If a .classpath already exists on import, or if the import wizard is configured to run the ‘eclipse’ task as part of importing. Some of the information that is in the generated .classpath _will_ be retained.

In STS 2.8.1 however source folders will be configured using the tooling API and existing generated source folders will be replaced by what tooling API returns. That being said… would tooling API not be expected to return source folders consistent with what eclipse task would generate? (Unless of course, the folders don’t actually exist).

In STS 2.9.0.RC1 there is now also an option to import with ‘dependency management’ disabled. This will retain most of the information generated by the gradle eclipse task ‘as is’. So assuming the generated .classpath is correct STS import should not mess with it. (But you’ll need to install 2.9.0.RC1 version of STS Gradle tools AND import with the dependency management disabled).

Kris
