apache / apache/maven-surefire

jdkToolchain cannot select from auto-discovered toolchains

Open
#3,382 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

### Affected version

3.5.6

### Bug description

When using the maven-toolchains-plugin auto discovery mechanism, surefire's `jvmToolchain` does not appear able to select one of the auto-discivered toolchains. It only seems to work with one statically defined in toolchains.xml which defeats the purpose of auto-discovery.

Not sure if this is due to a lifecycle constraint within Maven, or the toolchains plugin auto-discovery - or surefire itself. Manually binding the auto-discovery to before-test-classes somewhat allows to workaround, but that changes the default toolchain for any phase after that, which is not desirable as the toolchain selection is no longer scoped to the specific plugin.

The use case here is common - run Maven, plugins and perhaps compilation with (say) Java 25, but execute tests using an older JVM (say 11).
- allows use of modern compiler targeting older JVM to ensure newer Java deprecations are addressed
- allows plugins which require a higher JVM than your target Java version to run (e.g. modern `maven-bundle-plugin` needs Java 17) without restricting testing
- ensures code actually runs on older JVMs to handle JVM-specific runtime semantics correctly

Apologies if this is a duplicate, the toolchains documentation is not great, and intent is hard to decipher.

Contributor guide

Open the contributing guide

Research direction

Start with Surefire's jvmToolchain handling and Maven's maven-toolchains-plugin auto-discovery lifecycle, focusing on why auto-discovered toolchains are unavailable during test execution. Reproduce the Java 25 build with tests on Java 11, then verify that the selected JVM is scoped to Surefire without changing the default toolchain for later phases.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.