Skip to content

Conversation

desruisseaux
Copy link
Contributor

By default, java.util.jar.JarFile does not search for resources in META-INF/versions/ sub-directories. For enabling this feature, we need to specify a version greater than Java 8 to the constructor. The core change of this pull request is this line:

try (JarFile jar = new JarFile(path.toFile(), false, JarFile.OPEN_READ, target)) {
    // ...
}

The rest is for answering the question: "which target Java version"? An easy approach would have been to set target unconditionally to Runtime.version(), i.e. the Java version on which Maven is running. This pull request rather allows configuration, with the intend to set the target version to the value of the --release target option. This value can determine whether a dependency will be placed on the class-path or on the module-path. For example, if the module-info.class entry of a JAR file exists only in the META-INF/versions/17/ sub-directory, then the default location of that dependency will be the module-path only if the --release option is equal or greater than 17.

This pull request fixes the initial topic of apache/maven-compiler-plugin#966.

…ons/` sub-directories of a JAR file.

If the project specifies a target Java release, only the directories for versions equal to lower to the target version will be scanned.
* taken as a fallback.
*/
try (JarFile jar = new JarFile(path.toFile())) {
try (JarFile jar = new JarFile(path.toFile(), false, JarFile.OPEN_READ, target)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using JarFile(File), the default value for the verify argument is true. We're switching to false. Is that on purpose ? I don't really think we need signature verification at this point, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the JAR file is opened only for extracting the module name, either from the module-info.class or from the MANIFEST.MF file. I thought that verifying the JAR file was an overkill in that situation.

@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Oct 6, 2025
@gnodet gnodet merged commit f032cfe into apache:master Oct 6, 2025
19 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Oct 6, 2025
@gnodet
Copy link
Contributor

gnodet commented Oct 6, 2025

💔 Some backports could not be created

Status Branch Result
master Cherrypick failed because the selected commit (f032cfe) is empty. Did you already backport this commit?
maven-4.0.x

Manual backport

To create the backport manually run:

backport --pr 11153

Questions ?

Please refer to the Backport tool documentation

gnodet pushed a commit to gnodet/maven that referenced this pull request Oct 6, 2025
…ons/` sub-directories of a JAR file. (apache#11153)

If the project specifies a target Java release, only the directories for versions equal to lower to the target version will be scanned.

(cherry picked from commit f032cfe)
gnodet added a commit that referenced this pull request Oct 6, 2025
…ons/` sub-directories of a JAR file. (#11153) (#11206)

If the project specifies a target Java release, only the directories for versions equal to lower to the target version will be scanned.

(cherry picked from commit f032cfe)

Co-authored-by: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-4.0.x bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants