JDK Toolchain

Note that this page refers to hand-written JDK toolchains in ~/.m2/toolchains.xml. For a simpler setup, look at the JDK discovery mechanism.

Toolchain Description

The toolchain type id for JDK is "jdk".

Predefined <provides> identification tokens, for requirement matching in plugin configuration, are:

  • "version" marks the version of the JDK in toolchains.xml. In plugin's selection, this can be either a single version or a version range.
  • Other tokens are accepted, but only exact matches are supported.

In toolchains.xml, there is only one <configuration> element named "jdkHome". It designates the root directory of a JDK installation.

Sample ~/.m2/toolchains.xml setup

  1. <toolchains>
  2. <toolchain>
  3. <type>jdk</type>
  4. <provides>
  5. <version>11</version>
  6. <vendor>temurin</vendor>
  7. <purpose>for_mevenide</purpose>
  8. </provides>
  9. <configuration>
  10. <jdkHome>/Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home</jdkHome>
  11. </configuration>
  12. </toolchain>
  13. [...]
  14. </toolchains>

This defines a toolchain with version 11, vendor "temurin", and purpose "for_mevenide".

A project can request this toolchain by specifying the type "jdk" and the version "11". It can also use a version range that includes 11 like [8, 17]. It can also ask for the vendor temurin, with or without version, or the purpose "for_mevenide".

Toolchains Plugin Configuration

A project specifies a toolchain in the configuration of the maven-toolchains-plugin like so:

  1. <project>
  2. [...]
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-toolchains-plugin</artifactId>
  8. <version>3.2.0</version>
  9. <executions>
  10. <execution>
  11. <goals>
  12. <goal>toolchain</goal>
  13. </goals>
  14. </execution>
  15. </executions>
  16. <configuration>
  17. <toolchains>
  18. <jdk>
  19. <version>[1.8,)</version>
  20. </jdk>
  21. </toolchains>
  22. </configuration>
  23. </plugin>
  24. </plugins>
  25. </build>
  26. [...]
  27. </project>

In this example, the project is requesting any toolchain with type jdk that has a version of 1.8 or greater. "version" accepts any version range definitions. If you want exactly JDK 1.8 from the vendor temurin, the plugin would be configured like this:

  1. <configuration>
  2. <toolchains>
  3. <jdk>
  4. <version>1.8</version>
  5. <vendor>temurin</vendor>
  6. </jdk>
  7. </toolchains>
  8. </configuration>

Aside from version, the definitions are opaque strings. Maven looks in toolchains.xml for a toolchain that provides version=="1.8" and vendor=="temurin". It does not know or care what these strings mean. It does not, for instance, concern itself with whether the jdkHome configured by the toolchain that satisfies version=="1.8" and vendor=="temurin" is JDK 8 from the Temurin project, or JDK 21 from Oracle. JDK toolchain only checks that directory exists.

All conditions need to be satisfied to find a toolchain.