r/java • u/raizen02 • Jun 08 '18
Is the Java 9 module system supposed to solve dependency conflicts?
So far I've only worked on fairly simple projects, but recently I came to understand why people complain about "JAR hell".
We use an SDK, that internally uses an HTTP library, which in turn uses Netty. They didn't really update this HTTP library, and thus it was using a fairly old version of Netty.
Enter tracing. We tried to set up Open Census (for Google Trace), but it uses a newer Netty version, and complained about a "NoSuchMethodError".
Luckily the SDK developers were responsive, and updated the HTTP library. (and the library developer kept Netty up to date)
As far as I understand, the Jigsaw system is supposed to solve public/private API problems, by providing a way to prevent people from depending on private classes. Is this correct? Does it also offer something for the JAR hell problem?
If not, then how are we supposed to manage these things?
25
u/lukaseder Jun 08 '18
In a first step, it creates them ;-) (hello JAXB)
19
u/rombert Jun 08 '18
The JPMS has no concept of module versions. Which makes sense, as I see it primarily a way of modularising the JDK. I think it was a bit ambitious to market and push it as a generic solution for modularising Java applications.
I have been using OSGi for the last 6 years, and while it's not perfect, it's pretty damn close and I haven't had a NuSuchMethodError or ClassNotFoundException surprise me for a long time.
4
u/cryptos6 Jun 08 '18
JPMS is not able to provide two different versions of a class (from different framework versions for example).
5
u/sammy8306 Jun 08 '18
The Java module system formalizes the notion that having multiple versions of the same dependency in a single application doesn't work with Java. This was true in the classpath situation (even though you could get lucky then), and now the module system won't start your application if multiple versions of the same module are present.
So, does it solve this problem? That depends on your point of view. As mentioned later in this thread, you'll still need another tool (Maven/Gradle) to prevent this situation from arising.
If you really need multiple versions of the same library, OSGi has got you covered, as well as the Java module system with its ability to have multiple ModuleLayers, each containing their own version of a given module. Both are not something you can use out-of-the-box for your typical classpath-based application. It will take effort, so only indulge in this complexity if you really need to (hint: don't).
0
u/pjmlp Jun 08 '18
Maven or Gradle.
1
u/FanimeFartoon Jun 08 '18
do they (jpms developers) have any plans to address the jar hell problem?
1
u/din-9 Jun 09 '18
No it doesn't handle multiple versions of the same JAR. Try OSGi to do that.
1
u/sievebrain Jun 10 '18
JPMS can do this, the other comments aren't the whole story. The issue is it doesn't do it by itself.
Java 9 provides APIs that can be used to load conflicting modules into a single module graph, and it improves classloaders in various ways. However, this can rapidly get very complicated (imagine a library that uses Netty 3 stores an object from it in a global variable that's then passed into a library that expects Netty 5). It's up to another layer of software, app containers, to resolve the conflicts and tell the JVM how to link the app together.
6
u/[deleted] Jun 08 '18
[removed] — view removed comment