Skip to content
Advertisement

Choose which dependency to use in class

I want to use a class and in my pom there are two dependencies that support it: dependency1 and dependency2.
Using the class with dependency1 crashed my program, so I deleted it completely from pom and left dependency2 as it was and the code was working.
How do I tell maven to build my class with dependency2 and not dependency1, without deleting dependency1 (in case dependency1 contains something that I want to use in my code later on)?

Advertisement

Answer

You cannot sensibly use two libraries that contain classes with the same qualified class names.

So

  • either restrict yourself to one of them.
  • or use the Maven shade plugin to relocate the packages of one of the dependencies.
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement