desruisseaux commented on code in PR #1158:
URL:
https://github.com/apache/maven-compiler-plugin/pull/1158#discussion_r4241832617
##########
pom.xml:
##########
@@ -188,10 +188,88 @@ under the License.
<excludes>
<exclude>unit/**</exclude>
</excludes>
+ <!--
+ Tests run against the exploded classes directory, not the
packaged JAR.
+ The JVM's multi-release JAR dispatch does not apply to
directories, so
+ the JDK 24+ BytecodeAnalyzer override must be placed before the
root stub
+ on the classpath. We prepend META-INF/versions/24/ via the
classesDirectory parameter
+ so it is resolved before target/classes/ by the bootstrap class
loader.
+ -->
+
<classesDirectory>${project.build.outputDirectory}/META-INF/versions/24</classesDirectory>
+ <additionalClasspathElements>
+
<additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
+ </additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>enforce-java-build-version</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <requireJavaVersion>
+ <!--
+ Building this plugin requires JDK 25+ so that the
java.lang.classfile
+ classes in src/main/java24/ can always be compiled (with
release=24).
+ The compiled plugin JAR targets JDK 17 for main sources
and JDK 24
+ for the classfile-backed bytecode analyzer, and runs on
any JVM >= 17.
+ -->
+ <version>[25,)</version>
+ </requireJavaVersion>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <!--
+ Compile the java.lang.classfile-based bytecode analyzer (JDK 24+
API)
+ into META-INF/versions/24/ to form a proper multi-release JAR.
+ On JDK 24+, the JVM automatically loads the versioned
BytecodeAnalyzer
+ which delegates directly to ClassfileClassAnalyzer (no
reflection needed).
+ On JDK < 24, the root BytecodeAnalyzer stub is loaded instead,
which
+ reports isAvailable()=false and triggers a fallback to the
timestamp strategy.
+ JDK 25 is required at build time so this execution always runs.
+ -->
+ <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>
+
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/24</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
Review Comment:
We could replace all this block by Maven Complier 4 plugin. It would also be
a way to test our own work. Set the compiler plugin version to the latest
published 4.x version, delete the whole `<execution>` block and declare the
following instead in the `<build>` block:
```xml
<sources>
<source>
<directory>src/main/java</directory>
<targetVersion>17</targetVersion>
</source>
<source>
<directory>src/main/java24</directory>
<targetVersion>24</targetVersion>
</source>
</sources>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]