jetty.project
jetty.project copied to clipboard
Jetty maven plugin is not Maven toolchain aware
trafficstars
Jetty version(s) jetty-maven-plugin: all versions but checking the latest 9.x version: 9.4.49.v20220914 and latest 11.0.12 versions
Java version/vendor (use: java -version)
any, for e.g. 11.x or 17.x
OS type/version
Windows 11
Description When Maven toolchains are used, the jetty-maven plugin does not use the JDK specified there but uses the JDK which is used to build maven
How to reproduce?
- Create a toolchain.xml that specified multiple JDK versions. For e.g:
<?xml version="1.0" encoding="UTF-8"?>
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.17</version>
<vendor>oracle</vendor>
</provides>
<configuration>
<jdkHome>${JDK17_HOME}</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.11</version>
<vendor>oracle</vendor>
</provides>
<configuration>
<jdkHome>${JDK11_HOME}</jdkHome>
</configuration>
</toolchain>
</toolchains>
2.. Stick the toolchain.xml into your ~/.m2 folder. 3. In any jetty-maven supported project, add the toolchain plugin entry specifying a JDK version - say 17 in this example - in your build plugins section In you maven pom.xml:
<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>17</version>
<vendor>oracle</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
- Add any common jetty maven plugin to run the application to your pom.xml
- Run a maven build using a different JDK like JDK 11 (assign JAVA_HOME to this JDK, add JDK/bin folder this to the windows path)
- The jetty maven plugin will use JDK 11 thought the JDK 17 toolchain was specified and activated - the correct JDK 17 version will be used by the maven-compiler-plugin, surefire-plugin etc.