Ideally you should fix the dependencies in your projects so that you have exactly the right set of jars in the classpath. Take a look at how to exclude dependencies in Dependency Management chapter in the Gradle documentation.
If you still want to modify classpath entries for eclipse, here is one possible solution.
You can tinker with the .classpath
file generated by the eclipse
task in Gradle using the following:
eclipse.classpath.file {
withXml {
// This returns a the classpath XML root node (groovy.util.Node)
def node = it.asNode()
// Do the re-rodering of classpath entries by modifying the node object
}
}
Take a look at groovy.util.Node for methods you can use to view/modify the XML node.
Note that you will most likely not have any control over the classpath ordering done when you run the packaged application distribution in a JVM, which will pull you back to square one at runtime when the application actually runs.
Hence, the best solution is to find out the source of the jar dependency that you don't want in your classpath and eliminate it from there, rather than relying on classpath ordering which is risky and unreliable.