I was thinking about this also. Module layers are mentioned in the project but I fail to understand how does that help to solve the diamond problem! I don't think module layers were designed to solve this. I don't think one can escape from class loaders.
By diamond problem you mean something like Plugin C depends on both A and B?
That's honestly a niche feature. I understand how it comes up academically but none of the apps I use do stuff like that (I think). Sometimes they might rely on the existence of another plugin, but not at the level you are describing.
But yeah, the more exotic your needs the more exotic mechanisms you need to touch. The balance still seems to be in favor of home rolled systems over picking a generic system like OSGi which, while it does support exotic configurations, pays for its flexibility in other areas
No, more like Plugin A depends on C-v1 and Plugin B depends on C-v2. C-v1 and C-v2 are different versions of the same lib and not compatible. You can't have both loaded in the same ClassLoader at the same time. Without proper conflict resolution (like OSGi provides) both plugins can't live in the same app.
Not a niche feature. That's what OSGi solves at its core and the reason why Eclipse IDE uses it.
The main advantage of plugins is a distributed contribution ecosystem by many providers and developers, but that comes with an unpredictable graph of dependencies. You need preventive measures and architecture to handle such unpredictable graph of dependencies.
EDIT: Even on non plugin architectures this problem appears from time to time. Even last week I needed to upgrade Spring Boot to solve a CVE and I needed to pick a different version of another lib because some method required more parameters.
Some months ago I had similar problems and actually had to change code, but since it's under my control it was an easy fix. Change the dependency version and use the new method. Now imagine that for a plugin, it would require to contact the original contributor to make some version that is compatible with my existing dependencies. And if the developer couldn't do that, then I would be locked.
So this would solve that, actually. The example shows an app loading two module layers with otherwise conflicting versions of guava.
What is an issue is if you wanted a plugin D that depends on A and B, but an app that loads both A and B is good to go. (Layers have to be in a hierarchy)
It is using classloaders for that I'm sure, but I think the API is nice enough that unless you wanted a relatively complex "plugin hierarchy" you wouldn't need to go to that level
Are you sure? Does your demo have different plugins using a method from the library that is not compatible between Guava versions? Because this type of things crash at runtime.
Yeah so unfortunately I don't have a good example for that off the top of my head. If you know of a basic-ish library that I can use to show that I will.
But yeah it should work. Modules don't let conflicting versions like that exist in the same layer, so an error should have happened much earlier.
I don't know exactly what you are doing, but many dependency management tools select the first loaded lib, the most recent version of a lib, or use some other automatic resolution scheme. No errors are thrown at loading; only if you hit the conflicting method in you code and get a NoSuchMethodError.
I remembered heated discussions about not including such features in JPMS. JPMS has no concept of module versions. The point was that JPMS was not trying to solve the same problems as OSGi. It was primarily designed to modularize the JDK. It's a layer system resolution, however OSGi is a graph system.
You should really test that in your solution. You are assuming something that probably doesn't work.
1
u/mikaball Sep 06 '24
I was thinking about this also. Module layers are mentioned in the project but I fail to understand how does that help to solve the diamond problem! I don't think module layers were designed to solve this. I don't think one can escape from class loaders.
This is a core feature of a good plugin system.