gnodet commented on code in PR #3516:
URL: https://github.com/apache/maven-surefire/pull/3516#discussion_r4792374873


##########
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 =

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   Consider adding a comment to explain the fallback logic for future 
maintainers. This would make the behavior more explicit:
   
   ```java
   // If no configured toolchain matches the requirements, check if the 
toolchain
   // selected by the maven-toolchains-plugin in the build context matches.
   // This allows discovered JDKs to be used even when not in toolchains.xml.
   Toolchain toolchainFromBuildContext =
           getToolchainManager().getToolchainFromBuildContext("jdk", 
getSession());
   ```



##########
maven-surefire-plugin/src/site/markdown/examples/toolchains.md.vm:
##########
@@ -53,6 +53,10 @@ one that provides `1.8.0_504`, and `17` does not match 
`17.0.20`. JDKs discovere
 their full version, so use a range such as `[1.8,1.9)` or `[17,18)` to accept 
any update of a Java release. Other
 elements, like `vendor`, must equal the value in `toolchains.xml`.
 
+If no configured toolchain matches, ${thisPlugin} also checks the JDK 
toolchain selected in Maven's build context.

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   Good documentation update. The explanation is clear and accurately describes 
the new fallback behavior. One minor suggestion: consider clarifying that 
"matches" means the requirements are satisfied (e.g., version range includes 
the discovered JDK version), not just that the toolchain exists.



-- 
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]

Reply via email to