4 ms·
The problem is conflicting transitives, lib A depends on 29, B on 31.
by dtech 3y ago
The problem is conflicting transitives, lib A depends on 29, B on 31.
- ygra 3y agoDoes Java have a solution for such things where both libs can use their own version without them conflicting (unless they hand out Guava types to others, of course)? Custom class loaders?
- mrudolph22 3y agoJava doesn’t have a universal practical solution for this. Principled solutions based on custom class loaders (such as OSGi) added tremendous complexity and created more problems than they solved. Other solutions such as shading (renaming classes and their usages to prevent name conflicts between different versions) work in some cases but have their own limitations and drawbacks.
- aramattamara 3y agoWhat about Java modules (aka JEP-200, aka Project Jigsaw, completed in 2017)? Used it for JavaFX apps with no problems.
- mrudolph22 3y agoJava modules are fine but don’t offer a solution for version conflicts.
- ianlevesque 3y agoYes custom class loaders can solve this. Eclipse had an entire OSGI module system that did this among other things. In general though Java (and Kotlin) have been trending toward simpler and lighter though for years and I’d recommend just sorting out your dependencies, even drop some, to avoid that kind of thing.
- aramattamara 3y agoYes, it's called Java modules (aka JEP-200). Although people often skip it and put everything in one module. It was released in Java 9 (started in 2014 and completed fully in 2017).
- vips7L 3y agoAFAIK Jigsaw solves a different problem. The transitive dep will still be found on the module path.
- Someone 3y agoIn some cases, shading can also help. That, basically, renames a classes used in a jar. It has to be done by the creator of the jar, though. https://stackoverflow.com/a/49811665 https://stackoverflow.com/a/49811665: “If your uber JAR is likely to be used as a dependency in another application then there's a risk that the versions of the dependent classes in the uber JAR might clash with versions of those same dependencies in this other application. Shading helps to avoid any such issue by renaming the packages within the uber JAR” > unless they hand out Guava types to others, of course You still can hand out guava objects to others, as long as you hand them out as being of a standard Java interface. That will work as long as the receiver of the type uses instanceof with a class type or reflection, so it is a bit brittle. Technically, any breakage would indicate a bug in the receiving code, but fixing it cleanly may be impossible.
- paulddraper 3y agoAKA "diamond dependencies" Java 9 modules address this.
- deleted 3y ago[deleted]