jorsol commented on code in PR #57: URL: https://github.com/apache/maven-jar-plugin/pull/57#discussion_r1085296601
########## src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java: ########## @@ -225,23 +237,24 @@ public File createArchive() jarContentFileSet.setIncludes( Arrays.asList( getIncludes() ) ); jarContentFileSet.setExcludes( Arrays.asList( getExcludes() ) ); - boolean containsModuleDescriptor = false; String[] includedFiles = fileSetManager.getIncludedFiles( jarContentFileSet ); - for ( String includedFile : includedFiles ) + + // May give false positives if the files is named as module descriptor + // but is not in the root of the archive or in the versioned area + // (and hence not actually a module descriptor). + // That is fine since the modular Jar archiver will gracefully + // handle such case. + // And also such case is unlikely to happen as file ending + // with "module-info.class" is unlikely to be included in Jar file + // unless it is a module descriptor. + boolean containsModuleDescriptor = + Arrays.stream( includedFiles ).anyMatch( p -> p.endsWith( MODULE_DESCRIPTOR_FILE_NAME ) ); + + if ( detectMultiReleaseJar && Arrays.stream( includedFiles ).anyMatch( p -> p.startsWith( "META-INF" + SEPARATOR + + "versions" + SEPARATOR ) ) ) { - // May give false positives if the files is named as module descriptor - // but is not in the root of the archive or in the versioned area - // (and hence not actually a module descriptor). - // That is fine since the modular Jar archiver will gracefully - // handle such case. - // And also such case is unlikely to happen as file ending - // with "module-info.class" is unlikely to be included in Jar file - // unless it is a module descriptor. - if ( includedFile.endsWith( MODULE_DESCRIPTOR_FILE_NAME ) ) - { - containsModuleDescriptor = true; - break; - } + getLog().debug( "Adding 'Multi-Release: true' manifest entry." ); + archive.addManifestEntry( "Multi-Release", "true" ); Review Comment: In summary, no, we don't need to discover such case, if we detect the versioned area, we set the Manifest Entry. If the user already defined such configuration (as probably 99.9% of users might have right now) then it will be overridden by this setting, the `<manifestEntries>` section will become redundant since the _Maven Archiver_ handles this scenario using a `LinkedHashMap` and put the key and value on the Map. For those weird use-cases where the user don't want this behavior, the property `maven.jar.detectMultiReleaseJar` could be disabled. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org