Hello all! I believe this is not possible, but I j...
# gradle
c
Hello all! I believe this is not possible, but I just wanted to check; is there any chance that I could use two different versions of the same library in a project? The issue that I have is that a library that I’m using breaks if I use the new version of another one; and at the same time I wanted to use this new version in my project, since it has a couple of features that I need. Apart from this inception, how can I handle this scenario?
s
Not an easy problem to solve, because in almost all cases, two different versions of the same dependency will contain different versions of the same classes. The compiler and the runtime work on the assumption that for any given fully-qualified name, there can only be one class with that name.
Some libraries solve this problem by "shading", where they actually change the names of classes at build time, so that the two different versions of the class actually end up with two different names
That has its own drawbacks, though
This problem isn't specific to Kotlin (assuming you're using the JVM), so you should be able to find plenty of information elsewhere on the web
m
Yup, you'll want to take a look at https://github.com/johnrengelman/shadow. Assuming you have a lib that uses the
com.example
package, you'd use shadow to create a second jar that uses
com.example2
and update all your usages accordingly
Another solution would be to create separate ClassLoaders. That might work too
Both solutions will come with some caveats but it's doable theorically
c
Thank you for the suggestions! @Sam and @mbonnin, I’m going to give it a try 🙂