Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two libraries bring in different version of the same dependency. How to import them both?

I have the following situation:

+ DentistApp
   L TreatsLibrary
     L IceCream 1.0
   L CavityCausesLib
     L IceCream 2.0

Now I get a VerifyError because TreatsLibrary is using IceCream.giveToKidAfterDrill() which was removed in version 2.0 because of legal reasons.

How do I import both versions and make sure that each uses its own?

like image 740
gurghet Avatar asked Nov 10 '17 22:11

gurghet


1 Answers

This answer assumes you're talking about how to load these libraries from a packaged uber JAR at runtime.

You need to shade your dependencies using sbt-assembly. This can be done as follows:

assemblyShadeRules in assembly ++= Seq(
  ShadeRule.rename("IceCream.**" -> "my_icecream.@1")
    .inLibrary("com.library.treats" % "TreatsLibrary" % "1.0.0")
    .inProject
)

This will shade the IceCream dependency in your com.library.treats and change every package name to begin with my_icecream.

like image 194
Yuval Itzchakov Avatar answered Nov 16 '22 02:11

Yuval Itzchakov