I'm using an Eclipse workspace where I work on several projects that depend on each other, where some haven't been updated in a while and have older version dependencies.
- My Application
|
+- dep-a:2.10
|
+- My Main Library
| |
| +- dep-a:2.8
|
+- My Second Library
|
+- dep-a:2.0
That is not a problem for compiling because Maven understand that the application's pom.xml
depends on dep-a:2.10
and that overrides all older versions declared by the other dependencies.
But the classpath generated by Eclipse adds all dependencies from all projects, in order, so it looks something like this:
...:My Application/target/classes:dep-a-2.10.jar:…
...:My Main Library/target/classes:dep-a-2.8.jar:…
...:My Second Library/target/classes:dep-a-2.6.jar:…
Because the JVM prefers classes from later jars in the path to override earlier, classes are loaded from the older jars - and that breaks everything.
I tried adding explicit exclusions in the pom.xml
:
<dependencies>
<dependency>
<groupId>mypany</groupId>
<artifactId>My Main Library</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>external.dep</groupId>
<artifactId>dep-a</artifactId>
</exclusion>
</exclusions>
</dependency>
But that does nothing to the Eclipse launch configuration classpath - Eclipse just ignores that and adds all My Main Library
dependencies from the Eclipse project (in the workspace) for that library. I'm not even sure it understands that the "My Main Library" project in the workspace is the same thing as the pom.xml
dependency.
Is there a way to get Eclipse to stop bringing in duplicate jar dependencies?