Transitive dependency resolution in Java

I am trying to create a REST Dropwizard (Jersey) endpoint that interacts with HBase. Although these are my only two top-level dependencies, both of these dependencies are loaded with many transitive dependencies that conflict. A simple example of such a conflict is Google Guava:

  • HBase Client Specifies Version 11
  • Dropwizard points 18

Dropwizard will not work with version 11, and HBase will not work with version 18.

I looked at the documentation for the Maven shade plugin, but it doesn't seem to allow you to move classes found in dependency bars. Therefore, I do not know how to solve this problem without separating these two components into separate JVMs.

+6
source share
2 answers

This is a dirty decision. But you could ...

Create a project / module in which you define a set of service interfaces that your dropwizard will use to communicate with HBase.

Create another module / project that implements these interfaces and uses the HBase classes. The shadow of this project.

There is only an interface can in the Dropwizard project, but create a task to copy the shaded artifact to your resources.

Create a JARClassLoader for your shaded HBase client artifact. You may need to create a special subclass that does not pass to the parent object, because by default the class loader will ask the parent to allow the connection and may infer a newer version of guava from the external class loader.

Ask for a copy of the service contract from the Jar loader ...

Businessing api = Class.forName("com.awesome.Businessing", true, jarLoader).newInstance();

+1
source

Try specifying specific versions for these dependencies in the <dependencyManagement/> section of your pom.xml.

0
source

Source: https://habr.com/ru/post/988876/


All Articles