Skip to content

Addressing dependency clash

John Bogovic edited this page Jun 28, 2019 · 2 revisions

The pom-scijava bill of materials, in addition to declaring versions of components in the SciJava component collection, also adds necessary exclusions, so that you shouldn't have to. If you end up needing an exclusion, it's good to post on forum.image.sc about it to discuss whether we should add that exclusion to pom-scijava so that everyone benefits automatically, instead of stumbling over the same thing.

Dealing with duplicate classes found by the maven enforcer

This example will describe how to use eclipse to find and address duplicate classes that appear in dependencies that maven finds.

  1. Import this maven project into eclipse
  2. Navigate to the folder containing the "pom.xml" file, and run mvn
  3. Observe that you get the error below "No Duplicate Classes Allowed"
  4. Find the part of the error output telling us that it is the regexp and xalan dependencies that have duplicate classes
  5. Open the pom.xml in eclipse
  6. Open the "Dependency Hierarchy" tab.
  7. Type "xalan" into the Filter field near the top-right of the "Dependency Hierarchy" window, and see that we're depending on xalan-2.7.1
  8. Right click xalan-2.7.1 in the window, choose "Exclude maven artifact", and press "Ok"
  9. Save the pom.xml
  10. Notice that the pom.xml changed - look at what it did. (git diff will show what the changes are)
  11. Go back to the command line, run mvn and see that it works now!
  12. If you'd like, compare with the pom.xml in the solutions folder

Duplicate classes error

Notice that duplicate classes that cause the enforcer to complain were found in the dependencies: regexp and xalan.

No Duplicate Classes Allowed!
- For duplicate transitive dependencies, add dependency exclusions.
- For duplications between direct dependencies, resolve or add
  ignored classes to this rule's configuration.

  Found in:
    regexp:regexp:jar:1.3:runtime
    xalan:xalan:jar:2.7.1:runtime
  Duplicate classes:
    org/apache/regexp/ReaderCharacterIterator.class
    org/apache/regexp/REDebugCompiler.class
    org/apache/regexp/REDemo.class
    org/apache/regexp/RETest.class
    org/apache/regexp/REUtil.class
    org/apache/regexp/RESyntaxException.class
    org/apache/regexp/REDemo$1.class
    org/apache/regexp/RECompiler$RERange.class
    org/apache/regexp/StreamCharacterIterator.class
    org/apache/regexp/RECompiler.class
    org/apache/regexp/StringCharacterIterator.class
    org/apache/regexp/CharacterIterator.class
    org/apache/regexp/recompile.class
    org/apache/regexp/CharacterArrayCharacterIterator.class
    org/apache/regexp/REProgram.class
    org/apache/regexp/RE.class