How to change the generated Eclipse classpath for PDE projects?

We have some projects in our multiproject gradle build which actually represent Eclipse plugins. We compile and build them simply by normal classpath dependencies resolution, that is: declaring the needed target platforms jars as dependencies. This works well, even if this is not the strictly Eclipse way. But we do not have to care at build time, because the Eclipse way is handled at development time :slight_smile: by our brave developers.

My problem is generating the correct “.classpath” files for PDE based projects. This means: the classpath entries must not list any jars from the Gradle seen dependencies. Instead it just should have this entry:

<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

because Eclipse will resolve compile dependencies using the MANIFEST.MF.

I figured out I can add an entry this with this code:

eclipse.classpath.file {
  whenMerged { classpath ->
   if ('ui'== project.ext.ui) {
    withXml {
     def node = it.asNode()
     node.appendNode('classpathentry', 'kind="con" path="org.eclipse.pde.core.requiredPlugins"')
    }
       }
   }
 }

But I don’t know what to do if I want to get rid of the Eclipse target platform jars. And, of course, entries with “kind=‘src’” etc. must be kept. Do you have an example how to handle it?

The full Gradle distribution has some small samples. Additionally, it’s worth checking out examples on the usage of Groovy’s ‘XmlParser’, which this is based on.

There are several possible hooks where you can add your code to modify the way how classpath is generated. They are described in user guide and included is an example that removes some entries - you surely will find how to test what entries should stay and what needs to be removed based on their type and path. See http://www.gradle.org/docs/current/userguide/eclipse_plugin.html#N13F14

Ah yeah, thanks!

classpath.entries.removeAll { entry -> entry.kind == 'lib' }

is what I needed.

One minor thing is left. The new node which I create and append is coded as this:

node.appendNode('classpathentry', 'kind="con" path="org.eclipse.pde.core.requiredPlugins"')

The result in .classpath is decorated by xml entity codes “”" instead of simple using “”". Do I have a means to change this?

should read as

xml entity codes &quot;

node.appendNode(‘classpathentry’, [kind: ‘con’, path: ‘org.eclipse.pde.core.requiredPlugins’])

node.appendNode(‘classpathentry’, [kind: ‘con’, path: ‘org.eclipse.pde.core.requiredPlugins’])

The node is an instance of groovy.util.Node (http://groovy.codehaus.org/gapi/groovy/util/Node.html?is-external=true). Just use a different version of appendNode() to pass your attributes.

fine!