Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Maven Toolchain in native-image-maven-plugin
This adds support for Maven Toolchains in the native-image-plugin. Toolchains are the best practice for multi-module Maven projects where each module may need to build with a different Java version. For example, in a shared library project one might want to build most modules using a conservatively low Java version such as 1.8, to allow those libraries to be used by a larger population of developers. But within the same multi-module project you might have a "leaf" module that builds a standalone application and exports that application as an executable using GraalVM native-image. Toolchains allow each module to define the JDK flavour and version it requires. Toolchains are supported by all the basic Maven plugins such as maven-compiler-plugin, maven-surefire-plugin etc. Since the native-image plugin does not currently support toolchains, we have to run the entire Maven build using GraalVM as the JAVA_HOME, which may not work for some projects. To use this support, we can define a <toolchain> section in our $HOME/.m2/toolchains.xml such as: <toolchain> <type>jdk</type> <provides> <id>JavaSE-11</id> <version>11</version> <vendor>GraalVM</vendor> </provides> <configuration> <jdkHome>/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.0.0/Contents/Home</jdkHome> </configuration> </toolchain> Then in a module that uses GraalVM native-image we declare: <plugin> <artifactId>maven-toolchains-plugin</artifactId> <configuration> <toolchains> <jdk> <version>11</version> <vendor>GraalVM</vendor> </jdk> </toolchains> </configuration> </plugin> Note that if a module does not declare toolchain support, then the native-image-maven-plugin falls back to its existing mechanism, i.e. picking up the JAVA_HOME used to run Maven itself. Therefore, there will be no effect on existing projects that do not opt-in to using toolchains.
- Loading branch information