apache / apache/maven-surefire

[SUREFIRE-2112] Surefire not using toolchain JDK during test execution

Open
#2,841 1 comment 0 reactions 0 assignees View on GitHub
bug priority:minor
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

**[Ruan de Bruyn](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER293210)** opened **[SUREFIRE-2112](https://issues.apache.org/jira/browse/SUREFIRE-2112?redirect=false)** and commented

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 plugin, 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:

``
`    org.apache.maven.plugins`
`    maven-surefire-plugin`
`    3.0.0-M7`
`    `
`        /usr/lib/jvm/java-17-openjdk-amd64/bin/java`
`    `
``

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

---

**Affects:** 3.0.0-M7

**Attachments:**
- [surefire-bug-1.zip](https://issues.apache.org/jira/secure/attachment/13047097/surefire-bug-1.zip) (_6.68 kB_)

Contributor guide

Open the contributing guide

Research direction

Start by unpacking the attached surefire-bug-1.zip and reading its pom.xml and toolchains.xml. Reproduce the Java 17 project with the system Java 11 and inspect how the Surefire plugin selects the test JVM when the toolchains plugin is used. Done means tests execute with the selected JDK 17 toolchain without hardcoding the jvm path in pom.xml.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.