0

I have a java project with two maven modules (moduleA and moduleB), where each module want to access different versions (v1 and v2) of the same library. moduleA uses moduleB as a dependency. I created moduleB mainly to get around this problem and also thought it will keep the code well organized.

I have used maven shade plugin in moduleA's pom.xml, thinking it will help me differentiate the classes from each version but i still get "NoSuchMethodError" even though that method is available in v2 version of the library. Any help would be highly appreciated.

srini
  • 213
  • 1
  • 5
  • 12
  • 1
    You can't have 2 versions of your library at run-time. If it's not compatible, you need to choose a version and stick with it. – Tunaki Mar 03 '17 at 19:57
  • Look into this : http://stackoverflow.com/questions/4827335/different-versions-of-the-same-dependency-in-maven – Yohannes Gebremariam Mar 03 '17 at 19:59
  • you will have to use Maven-Shade-Plugin to rename the packages of the library in either moduleA or moduleB. Will only work if the library does not use Reflection or similar to access its own classes. – mihi Mar 03 '17 at 20:03
  • @mihi can you guide me how to do it ? I tried using `org.libraryorg.library_v2` under maven-shade-plugin in moduleB's pom.xml. as i wanted this version to be renamed. but i am still facing issues. – srini Mar 03 '17 at 22:24
  • Check the generated artifacts. Make sure that org.library_v2 gets packaged into the shaded artifact jar and that you do not depend on org.library Version 2 in your generated artifact POM (or it will include the unshaded version in the final classpath, making moduleA break). – mihi Mar 04 '17 at 22:02

1 Answers1

1

I don't think this can work: There's going to be namespace clash if you try to load two different versions of the same library into Java at one time

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80