I have a project with several utility classes. Let's name it Utils
.
I have a proj1
which depends on Utils
. And another proj2
that depends on proj1
and Utils
.
The problem is if both proj1
and proj2
depend on different Utils
version this will lead to problems.
What's the best solution?
This situation occurs in Scala/SBT projects, but I guess other languages have the same problems.
Edit:
Just to be clear,
proj2
is the project that will run, that uses some code fromproj1
andUtils
.
This is classic Jar Hell, and it is a problem on any JVM based project not just scala with sbt.
There are 4 common solutions
Get rid of conflict by changing code, consolidate your multiple version dependency into a single dependency.
Shading (as mentioned above by @Sean Viera)
Multiple ClassLoader component architecture like OSGI (as mentioned by @tuxdna)
Run in separate JVMs like a microservice architecture (also mentioned by @tuxdna)
You have three different projects:
The only way you can be 100%
sure that there are no conflicts between proj1 and proj2 is to run them in isolation.
As soon as you will mix proj1 and proj2 with different versions of Utils on the same classpath, you will end up override one or the other project.
You can achive isolation using:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With