#21510 closed enhancement (fixed)
[PATCH] Enable Multi-Release Jars (MRJAR AKA JEP 238)
Reported by: | taylor.smock | Owned by: | Don-vip |
---|---|---|---|
Priority: | normal | Milestone: | 21.12 |
Component: | Core | Version: | |
Keywords: | jep238 mrjar java9 | Cc: |
Description (last modified by )
From comment:15:ticket:21498 and comment:16:ticket:21498, it would be useful to be able to use new Java features while still maintaining backwards compatibility with Java 8.
JEP 238 allows for this. Java 8 reads the class files from the traditional package directories (e.g., org/openstreetmap/..
while Java9+ attempts to read class files first from META-INF/versions/${version}
, with ${version} starting at the java version (e.g., 11) and decrementing until it finds a class file or it reaches 8, at which point it reads it from the traditional package directory.
Pros:
- We can have version specific implementations for items, instead of having classes where each method has a check for the java version.
- We can try out newer Java features
- Specific to 360 imagery, we can try out the vectors (incubating) available in Java 17 (JEP 338 for Java 16, JEP 414 for Java 17, and JEP 417 for Java 18, JEP 426 for Java 19)
Cons:
- Testing -- each class file is essentially a duplicate, so we may have duplicated code when the class only has one or two methods that can or should be version specific
- The source code layout we have right now isn't very good for this use case. I've worked around it in the attached patch for
build.xml
, but IDEs are going to take a bit more work.- We may want to move the Java 8 source directories to
src/main/java
to make things easier. I was originally trying to have the source for Java{version} in the same source directory, but that didn't work well.
- We may want to move the Java 8 source directories to
What the attached patch does:
- Creates new macros:
call-javac-compile
andcall-javac-compile-mrjar
(the latter calls the former with some additional checks) - Checks for Java 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, and 21 source directories. These are expected to be
src/main/java-${version}
. If that directory exists, it compiles the files in that directory using the release target. The mrjar also checks that the compiler can compile for that version (isJava@{version}
is set).- I'll be attaching an additional patch without Java 9, 10, 12, 13, 14, 15, and 16, as all of those are no longer supported (OpenJDK) and are not LTS releases. While Java 18-21 are not yet released, they will remain as new features will be introduced in them. Java 18-20 should be removed as support is dropped for them.
EDIT: I tested that the build works by copying the Vector3D
class and adding a Logging.error
with a unique message for the non-JEP 238 class and one for the JEP 238 class.
Attachments (2)
Change History (13)
by , 3 years ago
Attachment: | 21510.patch added |
---|
by , 3 years ago
Attachment: | 21510.2.patch added |
---|
Same as attachment:21510.patch except without unsupported Java releases (still has future Java releases)
comment:1 by , 3 years ago
Description: | modified (diff) |
---|
comment:2 by , 3 years ago
Description: | modified (diff) |
---|
comment:3 by , 3 years ago
Milestone: | → 21.11 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
follow-up: 7 comment:6 by , 3 years ago
Thanks! Agreed in the long term I'd like to switch to conventional tree src/main|test/java|resources too, but that's another story :)
comment:7 by , 3 years ago
Replying to Don-vip:
Thanks! Agreed in the long term I'd like to switch to conventional tree src/main|test/java|resources too, but that's another story :)
Yep. Looks at all the patches.
comment:8 by , 3 years ago
Replying to Don-vip:
In 18309/josm:
Sorry about that -- I had some changes to build.xml
for use with my gitlab ci (mostly for codeclimate/source navigation).
comment:10 by , 2 years ago
Description: | modified (diff) |
---|
comment:11 by , 2 years ago
I'm going to investigate MRJAR support for #2372, I'd like to implement GeoTIFF support without waiting for Java 11/17 migration.
MRJAR support for all Java releases (Java 8 - Java 21)