Eclipse Plugin - Adding Classpath Entries Remove them Instead


(sirinath1978m) #1

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.

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:

<?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

<?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>

(Peter Niederwieser) #2

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


(sirinath1978m) #3

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.


(Peter Niederwieser) #4

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.


(sirinath1978m) #5

Shouldn’t

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

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


(Peter Niederwieser) #6

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


(sirinath1978m) #7

Sorry my bad.


(sirinath1978m) #8

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

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.


(Peter Niederwieser) #9

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


(sirinath1978m) #10

1.0 RC7


(Peter Niederwieser) #11

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.


(sirinath1978m) #12

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


(Kris De Volder) #13

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