Open maffe opened 2 years ago
The toolchains file can be generated using this Java code (requires Java 15 or higher):
import java.util.stream.Stream;
public class Toolchains {
public static void main(final String[] args) {
final String toolchains = """
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>%s</version>
<vendor>%s</vendor>
</provides>
<configuration>
<jdkHome>%s</jdkHome>
</configuration>
</toolchain>
</toolchains>""";
System.out.println(toolchains.formatted(Stream.of("version", "vendor", "home")
.map(s -> System.getProperty("java." + s))
.map(Toolchains::escapeXML1_0)
.toArray(Object[]::new)));
}
private static String escapeXML1_0(final String value) {
final StringBuilder sb = new StringBuilder(value.length());
value.codePoints().forEachOrdered(codePoint -> {
if (codePoint == '&') {
sb.append("&");
} else if (codePoint == '<') {
sb.append("<");
} else if (codePoint == '>') {
sb.append(">");
} else if (codePoint == '\'') {
sb.append("'");
} else if (codePoint == '"') {
sb.append(""");
} else if (codePoint == '\t' || codePoint == '\r' || codePoint == '\n'
|| (codePoint >= 0x20 && codePoint <= 0xD7FF)
|| (codePoint >= 0xE000 && codePoint <= 0xFFFD)
|| (codePoint >= 0x10000 && codePoint <= 0x10FFFF)) {
sb.appendCodePoint(codePoint);
} else {
sb.appendCodePoint(0xFFFD);
}
});
return sb.toString();
}
}
Save it as Toolchains.java
and run java Toolchains.java > /usr/share/maven/conf/toolchains.xml
This would not be required if the toolchains plugin checked if the toolchain request can be satisfied by the JDK Maven is running on.
Please prioritize this issue. Toolchain support is very important, all of the core plug-ins support it and many advanced Maven projects use toolchains.
It would be useful to have the JDK included in the default toolchains file.
Currently I have something like this in my
pom.xml
:When running
mvn clean package
inmaven:3-eclipse-temurin-17-alpine
, I get this error:Adding the following section to
/usr/share/maven/conf/toolchains.xml
resolved the issue:Values are taken from
mvn --version
, the<vendor>
element is not required,<version>
could also just include the major version (17
).