You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MTOOLCHAINS-44] Use default JDK if it matches the request and no other toolchain is defined #103
I’m not sure if it’s reasonable to do this in all cases or only if the toolchains file does not contain any toolchain. For example, if the toolchains file only contains a Java 16 toolchain and the project requires Java 17 (exactly, not 17 or later) and Maven is run with Java 17, it would be possible to build the project (with Java 17), but probably not a good idea since it will fail when the Java installation Maven is running on is updated to version 18.
My gut is that if a toolchain can't be located, we shouldn't simply use JAVA_HOME. Erroring is better here.
However, we might be able to define some defaults for certain JDK toolchains. The common case for toolchains is that the user wants a specific JDK version. If that's all they request, and toolchains.xml can't be found, or doesn't contain a matching JDK version, maven could still search in standard locations locally. For instance, suppose this is the configuration
The problem with this idea is that we can match JDK versions, but the configuration can have arbitrary other properties like vendor or willy_wonka. We have no way of matching anything else against the system installed libraries absent a toolchains.xml file.
That said, a jdk matched only by version is common enough that maybe we should special case that.
I noticed the toolchains plugin now has a JDK discovery mechanism. However it doesn’t work as I would expect after reading the documentation.
I don’t see any effect of {}<goal>select-jdk-toolchain</goal>{}. I thought it would set some internal state so the following <goal>toolchain</goal> would work, but that goal fails although mvn org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:display-discovered-jdk-toolchains finds the JDK matching the required version in the toolchains plugin configuration section (using the maven:3-eclipse-temurin-17-alpine Docker image).
Running mvn org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:generate-jdk-toolchains-xml generates ~/.m2/discovered-jdk-toolchains-cache.xml which does not seem to have any effect. However it works when renaming it to toolchains.xml.
Activity
jira-importer commentedon Feb 25, 2024
Elliotte Rusty Harold commented
My gut is that if a toolchain can't be located, we shouldn't simply use JAVA_HOME. Erroring is better here.
However, we might be able to define some defaults for certain JDK toolchains. The common case for toolchains is that the user wants a specific JDK version. If that's all they request, and toolchains.xml can't be found, or doesn't contain a matching JDK version, maven could still search in standard locations locally. For instance, suppose this is the configuration
{{ <configuration>
<toolchains>
<jdk>
<version>1.8</version>
</jdk>
</toolchains>
</configuration>}}
On a Mac you could run "/usr/libexec/java_home -V" to find a JDK that provides version 1.8.
jira-importer commentedon Mar 2, 2024
Elliotte Rusty Harold commented
The problem with this idea is that we can match JDK versions, but the configuration can have arbitrary other properties like vendor or willy_wonka. We have no way of matching anything else against the system installed libraries absent a toolchains.xml file.
That said, a jdk matched only by version is common enough that maybe we should special case that.
jira-importer commentedon Jan 23, 2025
dennis lucero commented
I noticed the toolchains plugin now has a JDK discovery mechanism. However it doesn’t work as I would expect after reading the documentation.
{}<goal>select-jdk-toolchain</goal>{}. I thought it would set some internal state so the following<goal>toolchain</goal>would work, but that goal fails althoughmvn org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:display-discovered-jdk-toolchainsfinds the JDK matching the required version in the toolchains plugin configuration section (using themaven:3-eclipse-temurin-17-alpineDocker image).mvn org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:generate-jdk-toolchains-xmlgenerates~/.m2/discovered-jdk-toolchains-cache.xmlwhich does not seem to have any effect. However it works when renaming it totoolchains.xml.