i have webapp i'm deploying in tomcat, 2 modules own dependencies. i'm running issue dependency of 1 of libraries in module older version required different library in module b. example, here dependencies in pom file:
module a:
<dependencies> <dependency> <groupid>org.example.com</groupid> <artifactid>librarya</artifactid> <version>1.0</version> </dependency> </dependencies>
module b:
<dependencies> <dependency> <groupid>org.another.com</groupid> <artifactid>libraryb</artifactid> <version>1.0</version> </dependency> </dependencies>
librarya depends on libraryc version 1.0, while libraryb depends on libraryc version 2.0. librarya not work new version of libraryc, , libraryb not work older version of libraryc. options have (if any) of having these modules live within same tomcat webapp, using different versions of these dependencies?
welcome jar hell. first, 2 potential quick wins:
- maybe can select intermediate version of libraryc
- maybe can migrate librarya , libraryb newest version of libraryc. if it's open source pull request
if it's not option have more work. rule of thumb: can't have different versions of same class. there no silver bullet there workarounds.
- splitting application. microservices architecture helps here lot of infrastructure around needed (monitoring, deployment, configuration etc)
- osgi. i've never used don't know if , how can integrate tomcat osgi platform better dependency management (including versioning)
- repackaging. there tools take existing source (not sure compiled classes) of library x.y.z , create mirror library a.b.c. after moment have different names can coexists easily. won't work every library of them refer using reflection
- different classloaders. may try load in application 1 classloader, libc v1 second 1 , libc v2 third one. may require customization, maybe custom classloaders. later may encounter compatibility problems class classloader 1 not instance of class classloader 2.