Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 900433 - java-pkg-simple.eclass: Support building multi-release JAR files [JEP 238]
Summary: java-pkg-simple.eclass: Support building multi-release JAR files [JEP 238]
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Java team
Depends on:
Reported: 2023-03-08 22:15 UTC by Yuan Liao (Leo3418)
Modified: 2023-03-08 22:21 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Yuan Liao (Leo3418) 2023-03-08 22:15:44 UTC
Many Java projects have adopted the *multi-release JAR file* standard (introduced by JEP 238 <>) to:
- Maintain compatibility with older Java major releases
- Leverage new features in the latest Java releases
- Avoid delivering multiple JAR files just for different Java major releases

For example, a multi-release JAR file can target Java 8 as the minimal supported release and, at the same time, include class files that are only compatible with Java 9 and above.  In this case, the class files compatible with only Java 9+ will not be loaded on Java 8.  Thus, users can switch between Java 8 and 9+ and reuse the same JAR file, instead of download a different JAR file for different Java major releases.

The multi-release JAR file standard is specified in the JAR File Specification:

java-pkg-simple.eclass should provide the functionality to create a multi-release JAR file, so ebuilds for Java projects whose upstream delivers multi-release JAR files can be easily created.
Comment 1 Yuan Liao (Leo3418) 2023-03-08 22:21:43 UTC
Extra Information That May Be Useful to This Functionality's Implementation

Summary of the multi-release JAR file standard:

- Definitions:

  - Multi-release JAR file:
    A JAR file in which the META-INF/MANIFEST.MF file bears the line:
        Multi-Release: true

  - Versioned directory:
    A 'META-INF/versions/<N>' directory in a multi-release JAR file,
    where <N> is the Java major release number (9, 10, 11, ..., 17, ...) that
    files under this directory target.

- Requirements:

  - "The public API exported by the classes in a multi-release JAR file must be
    exactly the same across versions".
    Interpretation: This eliminates the possibility where a class that is part
    of a public API is only available on certain latest Java major releases and
    not on older releases.  The public API's implementation may alter between
    different Java major releases to utilize the releases' latest features, but
    the API's interface may not.

The 'jar' tool itself naturally supports building a multi-release JAR file

    --release VERSION
        Creates a multirelease JAR file. Places all files specified after the
        option into a versioned directory of the JAR file named
        META-INF/versions/VERSION/, where VERSION must be must be a positive
        integer whose value is 9 or greater.

        At run time, where more than one version of a class exists in the JAR,
        the JDK will use the first one it finds, searching initially in the
        directory tree whose VERSION number matches the JDK's major version
        number. It will then look in directories with successively lower
        VERSION numbers, and finally look in the root of the JAR.

The same page also provides an example invocation of 'jar' that builds a
multi-release JAR file under the "Examples of jar Command Syntax" section.

Build systems like Maven and Gradle have been supporting building multi-release
JAR files already:
- Maven:
- Gradle: