Best practices for a "multi plugins" Java web application - Managing common libraries and conflictual versions

StackOverflow https://stackoverflow.com/questions/22130447

Question

I'm new on a web project where we have to develop plugins (called "extensions" in that specific project). The main application runs in a modified Tomcat web server and we have to add our plugins' .jars in a common lib folder. I'm still not very used to the application and how it works, but I'm pretty sure there is a common classloader for the application and all its plugins. All libraries in that lib folder are shared.

My question is how to deal with the plugins' dependencies and potentially conflictual versions, in that environment.

Should we have shared libraries for example some-common-lib-1.3.4 as jars in the lib folder and plugins have to use those versions when they need to use a library?

Or should a plugin contain its own dependencies (using Maven Shade Plugin for example) so different versions of a same dependency are not an issue?

The problem I see with having shared libraries with a specific version to use for all plugins, is about transitive dependencies. If a common library has a dependency to some-transitive-dependency-1.0.0 and we have a specific plugin which requires a new library which itself have a transitive dependency on some-transitive-dependency-2.0.0 then we're screwed... We would then need both some-transitive-dependency-1.0.0 and some-transitive-dependency-2.0.0 in the lib folder and who knows what will happen.

Also, if for one specific plugin we need to update a dependency to a new major version, we may have to update all plugins since that library is shared by all.

Any real world experience with such situation? Any tips?

No correct solution

OTHER TIPS

Since OSGI is not an option, and potentially everyone could create new plugins, the only feasible way to separate them is, as you already suggested, using the shade plugin or some similar technique.

Since you cannot separate classloaders and recompiling all plugins (for which you might not even have the source code) is really not an option and sometimes you might even have non-resolvable conflicts (asm 1.x and 2.x are totally incompatible), you have to use your own "poor-man's OSGI" and use shade.

Note, however, that this does reduce the option of plugins working together or sharing common data not defined in the main application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top