Maven standardized support for multi-releases jars

maven-jar-plugin
multi release jar
java multiple versions of same jar
maven multiple jars from one project
maven build multiple jars
jdeps multi-release
java use two versions of jar
maven publish multiple jars

Java 9 released with JEP-238, which basically allows us to ship multiple versions of runtime classes. The question is how this JEP is supported by maven?

  • I mean how and where to configure multiple versions in maven? I know I can run an ant task, but can I do it with say maven-compiler plugin or another standardized way?
  • And where and how should I place the different versions of java classes? JEP is constraining the compiled class files and say us where we should place it in jar but what about development?

I mean how and where to configure multiple versions in maven? I know I can run an ant task, but can I do it with say maven-compiler plugin or another standardized way?

I believe the maven-compiler-plugin is not the appropriate place to take care of the release or even if we say ant tasks. Its supposed to be compiling the sources of a project seeking the need of which it has though introduced a flag

-release N

whose usage seems similar to that of the -source N and -target N.

It shall compile for a specific VM version(N) and shall support targets: 6, 7, 8, 9. It is similar to the new flag introduced in javac as

--release <release>

The java way of creating a multi-release jar, placing some files in the META-INF/versions/9 directory after this shall be of the format :

jar --create --file mr.jar -C foo classes --release 9 -C foo9 classes

In terms of MR-JAR maven implementation, one of the alternates currently could be as linked by @simas or listed below as proposals(couldn't get to find their released implementations) in one of the analysis.

Note: Shouldn't one rather be interested in moving to JMODs instead of considering MR-JAR for versions 9 and later?

And where and how should I place the different versions of java classes?

In the document Java 9 and its Impact on Maven Projects, the proposals to solve for the MR-JAR has been to either keep a 1 to 1 translation to the structure as mentioned in the JEP-238

project root
 src/main/java
 - A.java
 - B.java
 - C.java
 - D.java
 src/main/java9
 - A.java
 - B.java
 src/main/java10
 - A.java

which though can work with different executions in maven but could possibly be inconvenient to be exposed to IDEs.

Another alternate with a sample hboutemy/maven-jep238 has been listed with the same to make use of following structure:-

multimodule root
 multirelease-base/src/main/java
 - A.java
 - B.java
 - C.java
 - D.java
 multirelease-nine/src/main/java
 - A.java
 - B.java
 multirelease-ten/src/main/java
 - A.java
 multirelease/src/assembly/mvjar.xml

October 4, 2017

I couldn't find an official documentation or implementation where these proposals are consumed by an open source/organisation, hence inferring its not very plainly possible using Maven currently.

Building Multi-Release JARs with Maven, I think that the IDEs, though, aren't going to add support until the layout is standardized. I like your layout best, as it seems most consistent with the  While javac, jar, java and other JDK tools already support multi-release JARs, build tools like Maven still need to catch up. Luckily, it can be done using some plug-ins for the time being, but it’s my hope that Maven et al. will provide proper support for creating MR JARs out of the box some time soon.

There are two examples how to process JEP-238 with Maven

  1. Example how to build JEP-238 oriented maven project organized as a multi-module one
  2. Example of single-module maven project with preprocessing

Apache Maven Compiler Plugin – Multi Release, With JEP-238 the support of multirelease jars was introduced. With the Multi-​Release: true flag in the MANIFEST file, the Java runtime will also Now every Maven module is just a standard Maven project with close to no  The Multi-Release: true attribute is only recognized when the classes are in a jar. In other words, you cannot test the classes put in target/classes/META-INF/versions/$ {release}/. Up until the moment of writing all IDEs can only have one JDK per Maven Project, whereas with multi release you want to specify it per source folder.

SLF4J seems to get this working with multiple modules.

Maven – Maven CI Friendly Versions, Starting with Maven 3.5.0-beta-1 you can use the `${revision}`, `${sha1}` and/or So now let us take a look into a situation where we have a multi module build. The multi-release-jar-maven-plugin compile goal has the same configuration properties as the classic maven-compiler-plugin. To compile the main sources as Java 8, you need to configure it as you would the maven compiler plugin, i.e. either using properties maven.compiler.source and maven.compiler.target set to 1.8.

JEP 238: Multi-Release JAR Files, Implement multi-release JAR files in the JRE, including support in the standard class loaders and JarFile API. Enhance other critical tools (e.g.,  Hi Russ, I think Hervés approach[1] is still the most cleanest possible solution. Main advantages: - works with every IDE as it is a standard multimodule project. - real unit testing for every version due to its isolation as Maven module.

How To Use Multi-release JARs To Target Multiple Java Versions , Build tools and IDEs don't really have good support for multi-release JARs, yet, but it's possible if you put in a little work:. Enhance the Java Archive Tool (jar) so that it can create multi-release JAR files. Implement multi-release JAR files in the JRE, including support in the standard class loaders and JarFile API. Enhance other critical tools (e.g., javac, javap, jdeps, etc.) to interpret multi-release JAR files. Support multi-release modular JAR files for goals 1

Creating Multi-Release JAR Files in IntelliJ IDEA, In the past, library developers had three options when it came to supporting newer versions of Java: Provide two (or more!) different JAR files, one  The .war contains some third party .jars, for example log4j-api-2.12.0.jar, that are multiple release .jars (per JEP 238, having Multi-Release: true in MANIFEST.MF). As such, it includes some Java 9 compiled classes in the META-INF/versions/9 directory. WebLogic 12.2 uses Java 8 only (confirmed version as Java 1.8.0_92 via WebLogic Admin Console).

Comments