You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/29 14:08:56 UTC
(maven-compiler-plugin) 01/01: fix: gate JDK 24 compilation and test behind java24+ profile
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch feature/abi-incremental
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git
commit 950b8605fda5abe2f80cc5040bb98ae67f15b8ef
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Sep 29 14:08:46 2026 +0000
fix: gate JDK 24 compilation and test behind java24+ profile
Move the compile-java24 execution from the main build section into a
java24+ activation profile (<jdk>[24,)</jdk>) so that builds on JDK 17
and 21 do not fail with 'release version 24 not supported'.
Guard the cross-validation test with @EnabledForJreRange(min = JAVA_24)
and instantiate ClassfileClassAnalyzer reflectively to avoid a
compile-time dependency on a class that only exists on JDK 24+.
---
pom.xml | 64 ++++++++++++----------
.../compiler/incremental/BytecodeAnalyzerTest.java | 15 ++++-
2 files changed, 49 insertions(+), 30 deletions(-)
diff --git a/pom.xml b/pom.xml
index 47638d30..fd1b326f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -192,37 +192,45 @@ under the License.
</plugin>
</plugins>
</pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <executions>
- <execution>
- <!--
- Compile sources that require java.lang.classfile (JDK 24+) separately
- with release=24, so the main sources stay at the baseline Java version.
- The compiled classes land alongside the main classes in the output directory.
- BytecodeAnalyzer loads ClassfileClassAnalyzer reflectively at runtime when
- the running JVM is JDK 24 or later; AsmClassAnalyzer is used otherwise.
- -->
- <id>compile-java24</id>
- <goals>
- <goal>compile</goal>
- </goals>
- <phase>compile</phase>
- <configuration>
- <compileSourceRoots>
- <compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot>
- </compileSourceRoots>
- <release>24</release>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
</build>
<profiles>
+ <profile>
+ <id>java24+</id>
+ <activation>
+ <jdk>[24,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <!--
+ Compile sources that require java.lang.classfile (JDK 24+) separately
+ with release=24, so the main sources stay at the baseline Java version.
+ The compiled classes land alongside the main classes in the output directory.
+ BytecodeAnalyzer loads ClassfileClassAnalyzer reflectively at runtime when
+ the running JVM is JDK 24 or later; AsmClassAnalyzer is used otherwise.
+ -->
+ <id>compile-java24</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <phase>compile</phase>
+ <configuration>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot>
+ </compileSourceRoots>
+ <release>24</release>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
<profile>
<id>run-its</id>
<build>
diff --git a/src/test/java/org/apache/maven/plugin/compiler/incremental/BytecodeAnalyzerTest.java b/src/test/java/org/apache/maven/plugin/compiler/incremental/BytecodeAnalyzerTest.java
index 84e2e83a..bd7ca877 100644
--- a/src/test/java/org/apache/maven/plugin/compiler/incremental/BytecodeAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/plugin/compiler/incremental/BytecodeAnalyzerTest.java
@@ -149,11 +149,16 @@ class BytecodeAnalyzerTest {
}
/**
- * When running on JDK 24+, {@link BytecodeAnalyzer} uses {@link ClassfileClassAnalyzer}
+ * When running on JDK 24+, {@link BytecodeAnalyzer} uses the {@code ClassfileClassAnalyzer}
* instead of {@link AsmClassAnalyzer}. Both must produce identical results for the same
* class file. This test cross-validates the two implementations against each other.
+ *
+ * <p>The {@code ClassfileClassAnalyzer} class is compiled with {@code --release 24} and
+ * only exists in the output directory when building on JDK 24+. To avoid a compile-time
+ * dependency on a class that may not exist, the analyzer is instantiated reflectively.
*/
@Test
+ @org.junit.jupiter.api.condition.EnabledForJreRange(min = org.junit.jupiter.api.condition.JRE.JAVA_24)
void asmAndClassfileAnalyzersProduceIdenticalResults() throws Exception {
CompilerTestHelper.writeSource(sourceDir, "test", "Subject", """
package test;
@@ -170,7 +175,13 @@ class BytecodeAnalyzerTest {
byte[] bytes = Files.readAllBytes(outputDir.resolve("test/Subject.class"));
var asmResult = new AsmClassAnalyzer().analyze(bytes);
- var cfResult = new ClassfileClassAnalyzer().analyze(bytes);
+
+ // Instantiate ClassfileClassAnalyzer reflectively — the class is only compiled on JDK 24+
+ ClassAnalyzer cfAnalyzer = (ClassAnalyzer) Class.forName(
+ "org.apache.maven.plugin.compiler.incremental.ClassfileClassAnalyzer")
+ .getDeclaredConstructor()
+ .newInstance();
+ var cfResult = cfAnalyzer.analyze(bytes);
assertEquals(asmResult.className(), cfResult.className(), "className");
assertEquals(asmResult.abiCanonical(), cfResult.abiCanonical(), "abiCanonical");