top | item 10196118

Java 9: The State of the Module System

122 points| pron | 10 years ago |openjdk.java.net | reply

57 comments

order
[+] skrebbel|10 years ago|reply
The cool thing is that compared to many languages/platforms, Java already has an excellent module system. Just look at the horrible hacks you have to go through in C++, Ruby or Python to manage multiple projects written in different versions of the language or with different versions of dependencies are just ridiculous, especially if you're developing on multiple platforms. Oh, you want to deploy it too? Have fun.

Let alone the IDE support. I think it's truly amazing that I can make a project with 3 different JVM languages and get instant IDE autocompletion and warnings when calling methods between those languages. The source -> .class -> .jar thing has turned out to be a remarkably visionary design (or just a very lucky hit). For comparison, C# still compiles and "tools" that much slower because .class files are missing in the pipeline.

It's a testament to some of the true goodness of Java, despite its unpopularity in hipper circles, that they don't think a Maven-managed folder full of JARs is good enough.

Of course, this is really a JVM thing and you'll also get it if you use a different JVM language so you can actually get the best of both worlds.

[+] EdSharkey|10 years ago|reply
Practically speaking, Maven (the executable tool) and pom.xml (the language) create a hot dependency mess when projects get past the toy stage. Maven makes most simple things impossible and a few challenges trivial. "Hamstrung" is the word that comes to mind. Coupling a declarative, own-the-world, XML programming language with innumerable slap-dash/poorly maintained plugins is the pits.

All that said, maven repositories and the groupId:artifactId:version:type:classifier organization of modules are really genius. As you say, this genius shines in IDE's where, as just one example, you get nice binary/source .jar distributions automatically downloaded to your local repo. Having an IDE's debugger be able to seamlessly and accurately step through 1st party java sources and 3rd party source .jar sources is always so impressive to me.

Gradle (and Ivy before it) help paper over the pain and expose the good parts of the maven ecosystem. I have some gripes with Gradle, but after seeing it in action (and now that IDE's can grok its project configs) I'm so happy to be ditching maven/plugins and hand-written pom's for the most part.

Java needs a holistic dependency management/dependency injection/artifact repository/publishing workflow rethink where well-defined concepts like semver are enforced in the version numbering scheme, making it easier to express "safe" legal version ranges in transitive dependencies.

[+] aabbccdd|10 years ago|reply
Are there any horrible hacks needed for Ruby to cope with dependencies? Is this something new or you're just ranting?
[+] pjmlp|10 years ago|reply
Yet another feature that Android devs won't get.

By the time Java 10 gets out, they can see how libraries that make use of modules, reified generics, value types, GPGPU integration, JIT plugins are out of reach.

Worse even, having library devs writing two versions of their libraries.

Google's fork of Java is leading to a Python 2 - 3 scenario.

[+] uxcn|10 years ago|reply
Is there an actual JSR for reified generics? I was under the impression that would generally break VM compatibility.

I have a hard time believing Google will stop supporting Java on Android, especially considering how widely they support it for other various platforms. I do know Go support for Android was recently released though.

[+] wiradikusuma|10 years ago|reply
Or, you know, you can use OSGi (http://www.osgi.org/Main/HomePage)
[+] wener|10 years ago|reply
Use complex to achieve simple, that's Java Style, :P
[+] smrtinsert|10 years ago|reply
That's a naive solution. OSGi has a very specific target of embedded applications. Thanks to its classloader, its a headache to port existing libraries which weren't written with its classloader in mind. This leads to duplicate osgi safe versions in custom artifact repos.

In the end, not a solution, but a very nice environment and development choice if you are greenfield and in the target audience.

[+] desdiv|10 years ago|reply
One motivation for the module system is faster JVM boot time. OSGi doesn't help with that at all.
[+] mateuszf|10 years ago|reply
Doesn't solve the versioning problem. That's a little disappointing.
[+] dj-wonk|10 years ago|reply
According to the article: "A module’s declaration does not include a version string, nor constraints upon the version strings of the modules upon which it depends. This is intentional: It is not a goal of the module system to solve the version-selection problem, which is best left to build tools and container applications."

I'm surprised by this as well. I was somewhat expecting Java 9 to tackle the dependency version problem.

[+] needusername|10 years ago|reply
My reading is it's hard enough as is because of backwards compatibility. They seem to be under massive pressure to deliver something for JDK 9 and can't push the deadline much longer.

If memory serves me correctly I remember Mark Reinhold saying to do it "right" they would have to run a linear equation solver like Eclipse/P2.

[+] norswap|10 years ago|reply
It is indeed a bit underwhelming, especially if you consider for how long it has been in the pipeline.
[+] smithkl42|10 years ago|reply
I've used C# for a long time, but have barely touched Java. How does this differ from the idea of "Assemblies" in the .NET world?
[+] pjmlp|10 years ago|reply
This is like .NET modules.

It will allow a group of jars to be exposed as a single entity, with internal APIs that can be exposed across jars, but not accessible outside the module.

[+] hitlin37|10 years ago|reply
is this the same module thing that's coming up in c++17( or later, it it doesn't make on time.)
[+] pjmlp|10 years ago|reply
No.

C++ modules are more like packages.

Java modules, which happen to exist in other languages like .NET, Delphi and Ada, are akin to having a set of dynamic libraries exposed as a single library. With the ability of having symbols that are only visible to the dynamic libraries that are part of the same module.

[+] pc2g4d|10 years ago|reply
Feels clunky doing require/export at the package level. Why not allow exporting of individual classes, for example?
[+] wener|10 years ago|reply
Will java drop the bc in the future ? (e.g. 1.4 1.5 1.6) With the time by, java have a heavier bc problem.
[+] codingvelocity|10 years ago|reply
I believe older java versions are already incompatible with newer jvms. I couldn't find it explicitly stated but i'd be surprised if 1.4 code worked 100% correct on a 1.7 jvm.

My experience so far is that the list of incompatibilities (http://www.oracle.com/technetwork/java/javase/compatibility-...) between versions makes it nearly impossible to just drop code between versions. It will run, but often implementation details have changed causing significant bugs. Your mileage may vary

[+] aardvark179|10 years ago|reply
If you watch talks like The Secret History and Tragic Fate of sun.misc.Unsafe ( https://www.youtube.com/watch?v=4HG0YQVy8UM ) you'll see that there is a move to isolate unsupported APIs and to slowly remove them once they are replaced by supported ones, but in general code that uses public APIs should continue to work without recompilation for a long time.
[+] krzyk|10 years ago|reply
What is "bc"?
[+] jonnw|10 years ago|reply
i really like how simple it is to declare the module metadata and how easy it is to read it