Ruan de Bruyn created SUREFIRE-2112:
---------------------------------------
Summary: Surefire not using toolchain JDK during test execution
Key: SUREFIRE-2112
URL: https://issues.apache.org/jira/browse/SUREFIRE-2112
Project: Maven Surefire
Issue Type: Bug
Components: Maven Surefire Plugin
Affects Versions: 3.0.0-M7
Environment: Ubuntu 22.04
Reporter: Ruan de Bruyn
Attachments: surefire-bug-1.zip
I am running an Ubuntu system, with several JDKs installed, but the "default"
one is JDK11 (i.e output of {{java -version}} in a shell is openjdk 11). I have
all of my installed JDKs defined in my toolchains.xml in my local .m2 folder.
In a Java 17 Spring Boot project, when I try to run {{mvn clean install}} and
specify the usage of JDK17 using the toolchains pluging, it compiles all source
and test classes, but does not run the tests. The error:
{{...has been compiled by a more recent version of the Java Runtime (class file
version 61.0), this version of the Java Runtime only recognizes class file
versions up to 55.0}}
It seems like surefire compiles the test code with JDK17, but tries to execute
them with my system's JDK11. If I skip the tests with {{mvn clean install
-DskipTests}} the build passes, and I see the compiled test classes. If I
hardcode my JDK17 location in the surefire plugin entry in the pom.xml, I can
get the build to pass:
{{<plugin>}}
{{ <groupId>org.apache.maven.plugins</groupId>}}
{{ <artifactId>maven-surefire-plugin</artifactId>}}
{{ <version>3.0.0-M7</version>}}
{{ <configuration>}}
{{ <jvm>/usr/lib/jvm/java-17-openjdk-amd64/bin/java</jvm>}}
{{ </configuration>}}
{{</plugin>}}
However, I would expect surefire-plugin to be aware of the Java 17 toolchain
I'm using, and execute the tests with JDK17, without having to specify the
correct JDK to use for test execution. I've attached a simple project that
recreates the issue, as well as a copy of my toolchains.xml file
--
This message was sent by Atlassian Jira
(v8.20.10#820010)