2

Does Java 9 modules can help with solving dependency conflict? I have included two dependencies, protobuf-java and protobuf-lite, they both contains the same classes under the same packages (FQN), the problem is implementations differs a bit from each other. Both dependencies comes from two different jars and i need both in single module. The problem is, that class loader takes just the first one on the classpath which leads to unexpected behavior like NoSuchMethodError or NoClassDefFoundError.

Do you have any idea how can I solve this problem? I guess i have to force loading these dependencies by different class loaders, right? Could you provide some examples which shows how to deal with it?

minizibi
  • 363
  • 2
  • 14
  • 1
    Your problem has a name: [Jar Hell](https://en.wikipedia.org/wiki/Java_Classloader#JAR_hell). This does not help much with regards to solving it, but it might make you feel a little better ;-) – Hulk Jan 12 '21 at 09:15
  • 1
    Why do you need both _protobuf-java_ and _protobuf-lite_? Is there no way you can just use one or the other? And no, JPMS does not really solve "Jar Hell" as I understand it (though JPMS would probably make your application fail at startup instead of some time later). – Slaw Jan 12 '21 at 09:16
  • 1
    Related (though about using different versions in *different* modules): https://stackoverflow.com/questions/45283886/using-different-versions-of-dependencies-in-separated-java-platform-modules – Hulk Jan 12 '21 at 09:18

0 Answers0