apache / apache/maven-surefire

[SUREFIRE-1976] Surefire fails when jdkToolchain is specified but no toolchains are configured

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

Description

**[Marcono1234](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=marcono1234)** opened **[SUREFIRE-1976](https://issues.apache.org/jira/browse/SUREFIRE-1976?redirect=false)** and commented

Surefire fails when using `jdkToolchain` but no toolchains are defined (no `.m2/toolchains.xml` file exists).
This differs from the behavior of other plugins, such as maven-compiler-plugin or maven-javadoc-plugin which fall back to using `getToolchainFromBuildContext`:
- [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin/blob/6335382f97aad2e69b9f9a0a4af3cf801cd29273/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java#L1467-L1470)
- [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin/blob/651b98e6951ee2e3d8fefa1bcb3629f1dae763be/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java#L2974-L2977)

(Though they do not verify that it matches the `jdkToolchain` constraints, which is also a bit questionable because you might then run into other issues during plugin execution because that toolchain is incompatible. And most likely there are other plugins out there which behave like Surefire regarding `jdkToolchain` support.)

This behavior is quite useful because it allows users without `toolchains.xml` to still build the project. My usecase for toolchains is currently to make sure that the JDK is >= JDK 11, which is most likely the case for most users. Though arguably the Maven Enforcer Plugin could be used for this (but then it might be a bit cumbersome for users which do actually have a `toolchains.xml` set up).

---

**Affects:** 3.0.0-M5

Contributor guide

Open the contributing guide

Research direction

Compare Surefire's jdkToolchain handling with the fallback calls shown in AbstractCompilerMojo.java and AbstractJavadocMojo.java. Locate the corresponding Surefire toolchain resolution and its tests; done means a missing .m2/toolchains.xml no longer causes failure when jdkToolchain is specified, with a regression test covering that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.