|
| 1 | +package org.gradlex.javamodule.moduleinfo.test |
| 2 | + |
| 3 | +import org.gradlex.javamodule.moduleinfo.test.fixture.GradleBuild |
| 4 | +import spock.lang.IgnoreIf |
| 5 | +import spock.lang.Specification |
| 6 | + |
| 7 | +class RealModuleJarPreservePatchingFunctionalTest extends Specification { |
| 8 | + |
| 9 | + @Delegate |
| 10 | + GradleBuild build = new GradleBuild() |
| 11 | + |
| 12 | + def setup() { |
| 13 | + settingsFile << 'rootProject.name = "test-project"' |
| 14 | + buildFile << ''' |
| 15 | + plugins { |
| 16 | + id("application") |
| 17 | + id("org.gradlex.extra-java-module-info") |
| 18 | + } |
| 19 | + application { |
| 20 | + mainModule.set("org.example") |
| 21 | + mainClass.set("org.example.Main") |
| 22 | + } |
| 23 | + ''' |
| 24 | + } |
| 25 | + |
| 26 | + @IgnoreIf({ GradleBuild.gradleVersionUnderTest?.matches("[67]\\..*") }) // requires Gradle to support Java 17 |
| 27 | + def "a real module cannot be extended via preserveExisting"() { |
| 28 | + given: |
| 29 | + buildFile << ''' |
| 30 | + tasks.withType<JavaCompile>().configureEach { |
| 31 | + options.compilerArgs.add("-Xlint:all") |
| 32 | + options.compilerArgs.add("-Werror") |
| 33 | + } |
| 34 | + dependencies { |
| 35 | + implementation("org.apache.logging.log4j:log4j-api:2.24.3") |
| 36 | + |
| 37 | + // required because not declared in LOG4J metadata |
| 38 | + compileOnly("com.google.errorprone:error_prone_annotations:2.36.0") |
| 39 | + compileOnly("com.github.spotbugs:spotbugs-annotations:4.9.0") |
| 40 | + compileOnly("biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0") |
| 41 | + compileOnly("org.osgi:osgi.annotation:8.1.0") // this includes 'org.osgi.annotation.bundle' |
| 42 | + } |
| 43 | + extraJavaModuleInfo { |
| 44 | + failOnMissingModuleInfo.set(false) // transitive dependencies of annotation libs |
| 45 | +
|
| 46 | + module("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j") { |
| 47 | + preserveExisting() |
| 48 | + requiresStatic("com.google.errorprone.annotations") |
| 49 | + requiresStatic("com.github.spotbugs.annotations") |
| 50 | + requiresStatic("biz.aQute.bnd.annotation") |
| 51 | + requiresStatic("org.osgi.annotation") |
| 52 | + } |
| 53 | + module("biz.aQute.bnd:biz.aQute.bnd.annotation", "biz.aQute.bnd.annotation") { |
| 54 | + requiresStatic("org.osgi.annotation") |
| 55 | + exportAllPackages() |
| 56 | + } |
| 57 | + module("org.osgi:osgi.annotation", "org.osgi.annotation") |
| 58 | + } |
| 59 | + ''' |
| 60 | + file("src/main/java/module-info.java") << """ |
| 61 | + module org.example { |
| 62 | + requires org.apache.logging.log4j; |
| 63 | + } |
| 64 | + """ |
| 65 | + file("src/main/java/org/example/Main.java") << """ |
| 66 | + package org.example; |
| 67 | + public class Main { |
| 68 | + org.apache.logging.log4j.message.ParameterizedMessage m; // needs errorprone |
| 69 | + org.apache.logging.log4j.status.StatusData d; // needs spotbugs |
| 70 | + org.apache.logging.log4j.util.SystemPropertiesPropertySource s; // needs aQute.bnd |
| 71 | + org.apache.logging.log4j.util.Activator a; // needs osgi |
| 72 | + |
| 73 | + public static void main(String[] args) {} |
| 74 | + } |
| 75 | + """ |
| 76 | + |
| 77 | + expect: |
| 78 | + run() |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments