r/java • u/ArturSkowronski • Oct 19 '22
Google will support OpenJDK development: the giant's investments in Java and Kotlin
https://vived.substack.com/p/google-will-support-openjdk-development41
u/cowwoc Oct 19 '22
I'll believe it once most of their libraries support Java Modules. The vast majority (maybe all) of their libraries are stuck in Java 8 which is a disaster. They could have added JPMS support while maintaining backwards compatibility with Java 8 but they repeatedly choose not to support anything newer than Java 8.
20
u/ArturSkowronski Oct 19 '22
Even Spring is stuck in pre-JPMS World. JPMS has long road ahead it.
Spring case is interesting, cause they needed to choose between JPMS and Native Images due to some strange mojo due to face they are so reflection-heavy.
21
u/cowwoc Oct 19 '22
Spring is a huge library with many sub-components. Most of Google libraries (e.g. Gauva) just need a single `module-info.java`, but they refuse to add it.
15
8
u/DJDavio Oct 19 '22
If their Devoxx talk is anything to go by, they have a strong single version mandate so everyone must be on Java 8 and migrating to a new version takes a long time. This kind of surprised me, but maybe because they have so many internal shared libraries it makes sense for them.
7
u/tristan957 Oct 19 '22
Could you explain how to add JPMS support while also supporting Java 8? I have open source Java bindings for an open source C API that I could add JPMS support to but haven't because honestly I didn't know about it.
9
u/cowwoc Oct 19 '22 edited Oct 20 '22
A recent change to Maven makes it very easy to build multi-release JARs. Check out https://issues.apache.org/jira/browse/MCOMPILER-417
and
3
u/tristan957 Oct 19 '22
I'm using Meson for my build system, so I'll probably need to add support for this there.
3
u/cowwoc Oct 19 '22
It's quite simple. You just need to add Java9-specific class into META-INF/versions/9/ in the JAR file.
See https://nipafx.dev/multi-release-jars-multiple-java-versions/
1
u/randjavadev Oct 21 '22
It is not. This will only work until it doesn't. The very concept of multi-release-jars was also introduced in Java 9, thus older systems can fail if they encounter classes within META-INF. If you must support older versions and systems (that you have no control over) than 9, the only foolproof way is to make a separate "JPMS" Java 9+ artifact of the lib that has the module.info (Automatic module name in the manifest will work in the same artifact, but it is not the same as a true module-info).
1
u/cowwoc Oct 21 '22
I'm not sure what you're basing this on. Many libraries use multi-release JARs and it is absolutely backwards compatible with older releases. Check out the Hikari JAR for one such example. Thousands of people use this without a hitch.
1
u/randjavadev Oct 24 '22 edited Oct 24 '22
On the fact that https://openjdk.org/jeps/238 lists "Release 9". In my mind that is all that matters, the concept doesn't exist until Java 9, thus it can only be used starting from Java 9, everything else is pure luck. But I guess you would want a practical example:
Proguard (or the maven plugin specifically here) didn't support MR jars: https://github.com/wvengen/proguard-maven-plugin/issues/61. Yes, that has been fixed in an update, but that was my whole point: when you make a library you do not control the target environment. Thus, if an user would be stuck with certain version of proguard maven plugin, they could never adopt a MR jar. Regardless they had to wait for an update to be made. MR jars are not backwards compatible, if they were, this problem would not have happened.
BouncyCastle has 2 separate artifacts, one multirelease and one not. https://www.bouncycastle.org/latest_releases.html " The jdk18on jars are compiled to work with anything from Java 1.8 up. They are also multi-release jars so do support some features that were introduced in Java 9, Java 11, and Java 15. If you have issues with multi-release jars see the jdk15to18 release jars below.". My point here is that why would they do this, unless their users have encountered problems with MR jars.
Also more examples you can google "meta-inf/versions/9 error".
Yes, probably these problems are very minority and probably nowadays solved by an update, but then it becomes the question that can you abandon your customers (if they cannot update their environments) that depend on your library or not. But for sure the MR jars are not 100%-backwards compatible with older environments that have not been updated to support it.
1
u/cowwoc Oct 24 '22
Your examples are very narrow edge-cases.
Proguard is very special case in that it takes class files as input. Anyone who does bytecode manipulation (Proguard, ASM, etc) will need to update their library. The vast majority of libraries do not fall into this category.
They did this because back in the day it was easier to build two separate JARs than building a multi-release JARs. This has nothing to do with backwards compatibility and is no longer the case today. As I highlighted above, all major build systems now support multi-release JARs.
Your third example is identical to the first: anyone doing bytecode manipulation will need to update their code. This is part of the reason I avoid such libraries, they are highly fragile, and in most cases you can achieve the same thing using build-time source-code generation (as JOOQ does, for example). Had they taken this route, their tool would have not broken on every new JDK release. Again, this is not specific to Java9 or multi-release JARs. This happens every single JDK release to tools that make use of bytecode manipulation. In my view, it's a silly thing to do when you have a safer alternative to build upon.
5
Oct 20 '22
Why do you care about JMPS? It’s not just Google, barely anyone uses it, even on Java 17
6
u/cowwoc Oct 20 '22
Asking why someone needs JPMS is like asking developers why they need access modifiers (public, package-private, private). It's all about providing a better API experience.
Access modifiers allow you to hide implementation details within a project. JPMS allows you to do so across projects. Many projects have internal or utilities packages that should not be used by end-users. JPMS enables developers to enforce this on an API level.
2
u/UnGauchoCualquiera Oct 22 '22 edited Oct 22 '22
I could be wrong but I always felt that it's a pretty losing proposition. People will inevitably use internal apis and you cannot prevent people from shooting their feet. Happened to acces modifiers and it will happen to modules too.
When there's a need there's a way around, even if unintended by the library author. Hidding behind a module just make it more annoying to do so as people can almost always just fork and mess around.
See the cat and mouse between lombok and java devs.
I think modules are aiming at improving java security by isolating modules more than preventing use of internals by programmers.
1
u/cowwoc Oct 22 '22 edited Oct 22 '22
Users can do whatever they want, but from the library author's perspective any use of internal APIs is unsupported. Also, from a code-complete and Javadoc perspective internal APIs never show up.
3
u/pjmlp Oct 20 '22
JMPS main goal was to modularizite the JVM implementation.
jlink and Graal rely on it.
19
u/DasBrain Oct 19 '22
Note that the title is a bit misleading:
Google has announced joining the Adoptium working group as a Strategic Member.
61
u/pjmlp Oct 19 '22
When they stop mucking around with Java on Android and support the language property, I will get it.
Until then it is only marketing.
Android 13 just got a subset of OpenJDK 11 LTS, released in 2018.