Maven - Toolchains
Table of Contents
Using maven toolchains to manage multiple JDK versions
Note: Always try to use the latest versions of the plugins in pom.xml to avoid incompatibility issues.
https://maven.apache.org/guides/mini/guide-using-toolchains.html
We need to have a toolchains.xml file that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>11</version>
<vendor>Oracle</vendor>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/amazon-coretto-11.jdk/Contents/Home</jdkHome>
</configuration>
</toolchain>
</toolchains>
We need to have this in your pom file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>11</version>
<vendor>Oracle</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
</project>