diff --git a/CHANGELOG.md b/CHANGELOG.md index 9de913e..239b0a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Extra Java Module Info Gradle Plugin - Changelog +## Version 1.10.1 +* [Fix] [#164](https://github.com/gradlex-org/extra-java-module-info/pull/164) - fix: 'preserveExisting' does not duplicate 'provides' entries + ## Version 1.10 * [New] [#160](https://github.com/gradlex-org/extra-java-module-info/pull/160) - Add 'preserveExisting' option to patch real modules * [New] [#140](https://github.com/gradlex-org/extra-java-module-info/pull/140) - Add 'removePackage' option to deal with duplicated packages diff --git a/src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java b/src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java index b1437ec..eed486a 100644 --- a/src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java +++ b/src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java @@ -396,7 +396,7 @@ public ModuleVisitor visitModule(String name, int access, String version) { return new ModuleVisitor(Opcodes.ASM9, moduleVisitor) { @Override public void visitEnd() { - addModuleInfoEntires(moduleInfo, providers, autoExportedPackages, this); + addModuleInfoEntires(moduleInfo, Collections.emptyMap(), autoExportedPackages, this); super.visitEnd(); } }; diff --git a/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPatchingFunctionalTest.groovy b/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPatchingFunctionalTest.groovy index 387faca..b12d606 100644 --- a/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPatchingFunctionalTest.groovy +++ b/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPatchingFunctionalTest.groovy @@ -1,7 +1,6 @@ package org.gradlex.javamodule.moduleinfo.test import org.gradlex.javamodule.moduleinfo.test.fixture.GradleBuild -import spock.lang.IgnoreIf import spock.lang.Specification class RealModuleJarPatchingFunctionalTest extends Specification { @@ -200,57 +199,4 @@ class RealModuleJarPatchingFunctionalTest extends Specification { out.output.contains("Patching of real modules must be explicitly enabled with 'patchRealModule()' and can only be done with 'module()'") } - @IgnoreIf({ GradleBuild.gradleVersionUnderTest?.matches("[67]\\..*") }) // requires Gradle to support Java 17 - def "a real module cannot be extended"() { - given: - buildFile << ''' - tasks.withType().configureEach { - options.compilerArgs.add("-Xlint:all") - options.compilerArgs.add("-Werror") - } - dependencies { - implementation("org.apache.logging.log4j:log4j-api:2.24.3") - - // required because not declared in LOG4J metadata - compileOnly("com.google.errorprone:error_prone_annotations:2.36.0") - compileOnly("com.github.spotbugs:spotbugs-annotations:4.9.0") - compileOnly("biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0") - compileOnly("org.osgi:osgi.annotation:8.1.0") // this includes 'org.osgi.annotation.bundle' - } - extraJavaModuleInfo { - failOnMissingModuleInfo.set(false) // transitive dependencies of annotation libs - - module("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j") { - preserveExisting() - requiresStatic("com.google.errorprone.annotations") - requiresStatic("com.github.spotbugs.annotations") - requiresStatic("biz.aQute.bnd.annotation") - requiresStatic("org.osgi.annotation") - } - module("biz.aQute.bnd:biz.aQute.bnd.annotation", "biz.aQute.bnd.annotation") { - requiresStatic("org.osgi.annotation") - exportAllPackages() - } - module("org.osgi:osgi.annotation", "org.osgi.annotation") - } - ''' - file("src/main/java/module-info.java") << """ - module org.example { - requires org.apache.logging.log4j; - } - """ - file("src/main/java/org/example/Main.java") << """ - package org.example; - public class Main { - org.apache.logging.log4j.message.ParameterizedMessage m; // needs errorprone - org.apache.logging.log4j.status.StatusData d; // needs spotbugs - org.apache.logging.log4j.util.SystemPropertiesPropertySource s; // needs aQute.bnd - org.apache.logging.log4j.util.Activator a; // needs osgi - } - """ - - expect: - build() - } - } diff --git a/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPreservePatchingFunctionalTest.groovy b/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPreservePatchingFunctionalTest.groovy new file mode 100644 index 0000000..ed055f7 --- /dev/null +++ b/src/test/groovy/org/gradlex/javamodule/moduleinfo/test/RealModuleJarPreservePatchingFunctionalTest.groovy @@ -0,0 +1,81 @@ +package org.gradlex.javamodule.moduleinfo.test + +import org.gradlex.javamodule.moduleinfo.test.fixture.GradleBuild +import spock.lang.IgnoreIf +import spock.lang.Specification + +class RealModuleJarPreservePatchingFunctionalTest extends Specification { + + @Delegate + GradleBuild build = new GradleBuild() + + def setup() { + settingsFile << 'rootProject.name = "test-project"' + buildFile << ''' + plugins { + id("application") + id("org.gradlex.extra-java-module-info") + } + application { + mainModule.set("org.example") + mainClass.set("org.example.Main") + } + ''' + } + + @IgnoreIf({ GradleBuild.gradleVersionUnderTest?.matches("[67]\\..*") }) // requires Gradle to support Java 17 + def "a real module cannot be extended via preserveExisting"() { + given: + buildFile << ''' + tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:all") + options.compilerArgs.add("-Werror") + } + dependencies { + implementation("org.apache.logging.log4j:log4j-api:2.24.3") + + // required because not declared in LOG4J metadata + compileOnly("com.google.errorprone:error_prone_annotations:2.36.0") + compileOnly("com.github.spotbugs:spotbugs-annotations:4.9.0") + compileOnly("biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0") + compileOnly("org.osgi:osgi.annotation:8.1.0") // this includes 'org.osgi.annotation.bundle' + } + extraJavaModuleInfo { + failOnMissingModuleInfo.set(false) // transitive dependencies of annotation libs + + module("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j") { + preserveExisting() + requiresStatic("com.google.errorprone.annotations") + requiresStatic("com.github.spotbugs.annotations") + requiresStatic("biz.aQute.bnd.annotation") + requiresStatic("org.osgi.annotation") + } + module("biz.aQute.bnd:biz.aQute.bnd.annotation", "biz.aQute.bnd.annotation") { + requiresStatic("org.osgi.annotation") + exportAllPackages() + } + module("org.osgi:osgi.annotation", "org.osgi.annotation") + } + ''' + file("src/main/java/module-info.java") << """ + module org.example { + requires org.apache.logging.log4j; + } + """ + file("src/main/java/org/example/Main.java") << """ + package org.example; + public class Main { + org.apache.logging.log4j.message.ParameterizedMessage m; // needs errorprone + org.apache.logging.log4j.status.StatusData d; // needs spotbugs + org.apache.logging.log4j.util.SystemPropertiesPropertySource s; // needs aQute.bnd + org.apache.logging.log4j.util.Activator a; // needs osgi + + public static void main(String[] args) {} + } + """ + + expect: + run() + } + +}