Skip to content

Commit ed393c4

Browse files
committed
Ignores MANIFEST.MF files not correctly positioned in Jar (#23)
1 parent aeb8552 commit ed393c4

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/functionalTest/groovy/de/jjohannes/gradle/javamodules/test/ExtraJavaModuleInfoTest.groovy

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,57 @@ class ExtraJavaModuleInfoTest extends Specification {
624624
new JarFile(shadowJar).entries().asIterator().size() == 5
625625
}
626626

627+
// See: https://github.com/jjohannes/extra-java-module-info/issues/23
628+
def "ignores MANIFEST.MF files that are not correctly positioned in Jar"() {
629+
given:
630+
new File(testFolder.root, "src/main/java/org/gradle/sample/app/data").mkdirs()
631+
632+
testFolder.newFile("src/main/java/org/gradle/sample/app/Main.java") << """
633+
package org.gradle.sample.app;
634+
635+
public class Main {
636+
public static void main(String[] args) throws Exception {
637+
}
638+
}
639+
"""
640+
641+
testFolder.newFile("src/main/java/module-info.java") << """
642+
module org.gradle.sample.app {
643+
requires com.google.javascript.closure.compiler;
644+
}
645+
"""
646+
testFolder.newFile("build.gradle.kts") << """
647+
plugins {
648+
application
649+
id("de.jjohannes.extra-java-module-info")
650+
}
651+
652+
repositories {
653+
mavenCentral()
654+
}
655+
656+
java {
657+
modularity.inferModulePath.set(true)
658+
}
659+
660+
dependencies {
661+
implementation("com.google.javascript:closure-compiler:v20211201")
662+
}
663+
664+
extraJavaModuleInfo {
665+
automaticModule("closure-compiler-v20211201.jar", "com.google.javascript.closure.compiler")
666+
}
667+
668+
application {
669+
mainModule.set("org.gradle.sample.app")
670+
mainClass.set("org.gradle.sample.app.Main")
671+
}
672+
"""
673+
674+
expect:
675+
build().task(':compileJava').outcome == TaskOutcome.SUCCESS
676+
}
677+
627678
BuildResult build() {
628679
gradleRunnerFor(['build']).build()
629680
}

src/main/java/de/jjohannes/gradle/javamodules/ExtraModuleInfoTransform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private static Map<String, String[]> copyAndExtractProviders(JarInputStream inpu
164164
if (entryName.startsWith(SERVICES_PREFIX) && !entryName.equals(SERVICES_PREFIX)) {
165165
providers.put(entryName.substring(SERVICES_PREFIX.length()), extractImplementations(content));
166166
}
167-
if (!JAR_SIGNATURE_PATH.matcher(jarEntry.getName()).matches()) {
167+
if (!JAR_SIGNATURE_PATH.matcher(jarEntry.getName()).matches() && !"META-INF/MANIFEST.MF".equals(jarEntry.getName())) {
168168
outputStream.putNextEntry(jarEntry);
169169
outputStream.write(content);
170170
outputStream.closeEntry();

0 commit comments

Comments
 (0)