gnodet commented on code in PR #3516:
URL: https://github.com/apache/maven-surefire/pull/3516#discussion_r4792370429
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java:
##########
@@ -1120,12 +1121,20 @@ private Toolchain getToolchain() throws
MojoFailureException {
if (getJdkToolchain() != null) {
List<Toolchain> tcs =
getToolchainManager().getToolchains(getSession(), "jdk", getJdkToolchain());
- if (tcs.isEmpty()) {
- throw new MojoFailureException(
- "Requested toolchain specification did not match any
configured toolchain: "
- + getJdkToolchain());
+ if (!tcs.isEmpty()) {
+ tc = tcs.get(0);
+ } else {
+ Toolchain toolchainFromBuildContext =
+
getToolchainManager().getToolchainFromBuildContext("jdk", getSession());
+ if (toolchainFromBuildContext instanceof ToolchainPrivate
+ && ((ToolchainPrivate)
toolchainFromBuildContext).matchesRequirements(getJdkToolchain())) {
+ tc = toolchainFromBuildContext;
+ } else {
+ throw new MojoFailureException(
+ "Requested toolchain specification did not match
any configured toolchain: "
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
The error message could be more informative. Currently, it doesn't
distinguish between:
1. No build context toolchain exists
2. Build context toolchain exists but doesn't match requirements
3. Build context toolchain exists but is not a ToolchainPrivate instance
Consider something like:
```java
if (toolchainFromBuildContext == null) {
throw new MojoFailureException(
"Requested toolchain specification did not match any configured
toolchain and no toolchain is available from build context: "
+ getJdkToolchain());
} else if (!(toolchainFromBuildContext instanceof ToolchainPrivate)) {
throw new MojoFailureException(
"Requested toolchain specification did not match any configured
toolchain and build context toolchain does not support requirement matching: "
+ getJdkToolchain());
} else {
throw new MojoFailureException(
"Requested toolchain specification did not match any configured
toolchain or the build context toolchain: "
+ getJdkToolchain());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]