0

Getting a class not found error at runtime due to maven sub dependency issue:

I am working on integrating twilio sdk ( com.twilio.sdk:twilio:7.35.0 ) into a multi module maven(3.x)/java(java8) project. I firstly added the twilio maven dependency to the corresponding module And I am getting a class not found exception at runtime on org.apache.http.conn.HttpClientConnectionManager. I looked into it and found out that this class is part of org.apache.httpcomponents:httpclient (which is a subdependency in the twilio sdk ) and that an earlier version of this dependency is in my project. And this earlier version does not have the HttpClientConnectionManager class.

So from this point, I tried to exclude the old version of the dependency with exclude tag first then with maven enforcer plugin and in the same time importing the dependency directly but nothing worked. I tried to import the dependency in the parent pom and in the other modules that are using my twilio module as well.

I am using twilio 7.35 which uses org.apache.httpcomponents:4.5.6 but in my multi-module project I am using org.apache.cassandra:cassandra-thrift:3.0.0 which is using thrift:0.9.2 which contains the old version of httpclient(4.2.5). The latest version of this cassandra module does not support the latest version of httpClient, so I need to make sure this httpclient older dependency does not mess up the twilio one.

I also analysed the output of mvn dependency:tree -Dverbose and it seems that the 4.5.6 is getting picked up correclty. And when I tried adding it to the parent module or the calling module, I can see that the old version is getting overwritten by the twilio one but it does not solve my issue.

I am starting to wonder if it is even possible to have two versions of the dependencies in the same maven project.

tatatan
  • 3
  • 1
  • Please provide a minimum viable example. Checkout https://stackoverflow.com/help/mcve for more details! – Mark Mar 20 '19 at 21:05
  • In Maven, you can only have one version of a dependency in the dependency tree at the same time. There are ugly work-arounds with the maven shade plugin, though. – J Fabian Meier Mar 21 '19 at 09:55

1 Answers1

0

It sounds like you are experiencing something similar to a related question dealing with Jar Hell: Jar hell: how to use a classloader to replace one jar library version with another at runtime

In this case you need to use a separate classloader from the default one in your project. Perhaps you could use the URL Classloader and load some or all of your newer dependencies from the filesystem.

Andre Lewis
  • 396
  • 1
  • 4
  • 10