Skip to content

jdkToolchain cannot select from auto-discovered toolchains #3382

Description

@chadlwilson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions