News for hackers. Stuff that matters.
Re:Guava: Google core libraries for Java by ygra on Wednesday November 08, 2023 @05:07PM (#38197808)
Does 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?
Re:Guava: Google core libraries for Java by mrudolph22 on Wednesday November 08, 2023 @05:27PM (#38198075)
Java 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.
Re:Guava: Google core libraries for Java by aramattamara on Wednesday November 08, 2023 @05:48PM (#38198345)
What about Java modules (aka JEP-200, aka Project Jigsaw, completed in 2017)?

Used it for JavaFX apps with no problems.

Re:Guava: Google core libraries for Java by mrudolph22 on Thursday November 09, 2023 @12:48AM (#38201623)
Java modules are fine but don’t offer a solution for version conflicts.
Re:Guava: Google core libraries for Java by ianlevesque on Wednesday November 08, 2023 @05:28PM (#38198096)
Yes 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.
Re:Guava: Google core libraries for Java by aramattamara on Wednesday November 08, 2023 @05:46PM (#38198323)
Yes, 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).

Re:Guava: Google core libraries for Java by vips7L on Wednesday November 08, 2023 @06:12PM (#38198599)
AFAIK Jigsaw solves a different problem. The transitive dep will still be found on the module path.
Re:Guava: Google core libraries for Java by Someone on Wednesday November 08, 2023 @06:47PM (#38198918)
In 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:

“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.

Re:Guava: Google core libraries for Java by paulddraper on Wednesday November 08, 2023 @06:47PM (#38198926)
AKA "diamond dependencies"

Java 9 modules address this.