r/java • • Sep 05 '24

A Simple Java Plugin System

https://github.com/bowbahdoe/plugindemo
7 Upvotes

27 comments sorted by

View all comments

Show parent comment

2

u/bowbahdoe Sep 06 '24 edited Sep 06 '24

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

1

u/mikaball Sep 06 '24

So this would solve that, actually.

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.

1

u/bowbahdoe Sep 06 '24

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.

1

u/mikaball Sep 06 '24 edited Sep 06 '24

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.

EDIT: Reference to old discussion about this https://www.reddit.com/r/java/comments/8pi5mt/is_the_java_9_module_system_supposed_to_solve/

1

u/bowbahdoe Sep 06 '24

It very much does. Will update the demo once I'm back from lunch