6

I have a critical classpath order issue due to which I need to ensure a JAR 1 comes before JAR 2 in the classpath.

Is there a way to enforce this in the GRADLE_DEPENDENCIES in the Eclipse IDE.

Any insights into how the same can be achieved during packaging the application (distribution) ?

acthota
  • 557
  • 5
  • 22
  • Yes, you can do it by dependencies, but notice two rules of the higher priority: http://stackoverflow.com/a/38743046/715269 – Gangnus Aug 03 '16 at 12:03

1 Answers1

7

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.

Invisible Arrow
  • 4,625
  • 2
  • 23
  • 31
  • Thanks for the well rounded answer. I have realized that the problem is due to a version conflict of a jar which is being added as a transitive dependency. I have solved the problem by excluding it in the dependency declaration using the "exclude" functionality. Thanks again for the informative answer. – acthota Jan 12 '15 at 02:47