This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git
commit a41d8146faad0cf6952376df69796a97e5984d7a Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Thu Nov 5 01:18:13 2026 +0000 Use ALL-UNNAMED in the jpms add-exports fixture and make the test rerunnable --- .../java/org/apache/maven/plugin/compiler/CompilerMojoTest.java | 9 ++++++--- .../org/apache/maven/plugin/compiler/TestCompilerMojoTest.java | 3 ++- .../resources/unit/compiler-jpms-add-exports/plugin-config.xml | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java index 6d455db2..c2a22ae7 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java @@ -31,6 +31,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.compiler.stubs.CompilerManagerStub; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; @@ -352,13 +353,15 @@ class CompilerMojoTest { void testJpmsAddExports(CompilerMojo compilerMojo) throws Exception { setUpCompilerMojoTestEnv(compilerMojo); - // output of earlier runs stays under target/, so start without it + // The mojo only writes jpms.args when it compiles, and only logs a warning when it cannot write it, while + // target/ keeps the classes of earlier runs (the next run would find nothing to compile). Start from an empty + // output directory so the assertion reads this run's file. + FileUtils.deleteDirectory(compilerMojo.getOutputDirectory()); Path jpmsArgs = compilerMojo.getOutputDirectory().toPath().resolve("META-INF/jpms.args"); - Files.deleteIfExists(jpmsArgs); compilerMojo.execute(); - assertEquals(Arrays.asList("--add-exports", "app/org.maven.test=ALL_UNNAMED"), Files.readAllLines(jpmsArgs)); + assertEquals(Arrays.asList("--add-exports", "app/org.maven.test=ALL-UNNAMED"), Files.readAllLines(jpmsArgs)); } private void setUpCompilerMojoTestEnv(CompilerMojo mojo) throws Exception { diff --git a/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java b/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java index 22cdaa9d..08e5b1de 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java @@ -217,7 +217,8 @@ class TestCompilerMojoTest { Arrays.asList(fixture.resolve("src/test/java").toString())); setVariableValueToObject(testCompilerMojo, "testPath", Arrays.asList(mainClasses.toString())); - // output of earlier runs stays under target/, so start without it + // The mojo only logs a warning when it cannot write jpms.args, and target/ keeps the file of earlier runs. + // Delete it so the assertion cannot pass on a stale file. Path jpmsArgs = testCompilerMojo.getOutputDirectory().toPath().resolve("META-INF/jpms.args"); Files.deleteIfExists(jpmsArgs); diff --git a/src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml b/src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml index 1b435b2e..8d0edd53 100644 --- a/src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml +++ b/src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml @@ -32,7 +32,7 @@ <buildDirectory>${basedir}/target/test/unit/compiler-jpms-add-exports/target</buildDirectory> <compilerArgs> <arg>--add-exports</arg> - <arg>app/org.maven.test=ALL_UNNAMED</arg> + <arg>app/org.maven.test=ALL-UNNAMED</arg> </compilerArgs> </configuration> </plugin>
