Eclipse plugin: add new element to a classpathentry


(pascal.stieber) #1

Hey guys,

i’m messing around with the eclipse plugin for days. hope sb. can help me! my problem: when i create the .classpath file it would be nice to add a new element in an classpathentry. each classpathentries containing my project depedencies should contain a new src element which refers to the *-src.jar.

concrete example: actual:

what i want:

i hope somebody can help !?!?


(pascal.stieber) #2

i am sry. the example seems to get lost!

a new trial: actuall:

<classpathentry kind="src" path="/someDependendComponent" exported="true"/>

what i want:

<classpathentry kind="src" path="/someDependendComponent" exported="true" src="path/to/dependendComponent-src.jar"/>

(Peter Niederwieser) #3

Is this for dependencies that aren’t available from a Maven or Ivy repository? Otherwise you should get this for free.


(pascal.stieber) #4

yes, you are right. this are project dependencies and they’re not available from a repository. but i need its src path. how can i add this?


(Rolf Suurd) #5

There might be a more ‘groovy’ way to do it but you can adjust the actual .classpath file ‘by hand’ like this:

eclipse {
    classpath {
        file {
            withXml {
                def node = it.asNode()
                node.appendNode('classpathentry', [kind: 'src', path: 'some/path', exported: true, src: 'path/to/component-src.jar'])
            }
        }
    }
}

(pascal.stieber) #6

i solved this problem as follows:

whenConfigured { classpath ->
 classpath.entries.findAll{entry -> entry.kind == 'src' && entry.exported == true}.each{
  def componentName = it.path
  def sourcePath = fileTree("${rootDir}/${componentName}/build/libs").findAll{it.name.endsWith("src.jar")}
              withXml {
            def node = it.asNode()
          node.appendNode('classpathentry', [kind: 'src', path: componentName, exported: true, sourcepath: sourcePath.join()])
     }
     }
      classpath.entries -= classpath.entries.findAll{entry -> entry.kind == 'src' && entry.exported == true}
}

it would be nice if this workaround would be a part of the plugin.