Skip to content

JDK discovery mechanism now working as expected #62

Open

Description

@4r73m190r0s

Affected version

3.2.0

Bug description

Executing mvn org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:display-discovered-jdk-toolchains works, and returns all JDKs installed on my machine, but I don't know how to cinfigure Maven to use Java 8 for project runtime.

This auto discovery mechanism should work without ~/.m2/toolchains.xml file per documentation.

My goal is to run project with Java 8.

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.18</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.username.mock</groupId>
	<artifactId>webserver</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>webserver</name>
	<description>Demo project for Spring Boot</description>
	<url/>
	<licenses>
		<license/>
	</licenses>
	<developers>
		<developer/>
	</developers>
	<scm>
		<connection/>
		<developerConnection/>
		<tag/>
		<url/>
	</scm>
	<properties>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-toolchains-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <goals>
              <goal>select-jdk-toolchain</goal>
            </goals>
            <configuration>
              <discoverToolchains>true</discoverToolchains>
              <runtimeVersion>8</runtimeVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
	</build>
</project>

Error I get with mvn spring-boot:run:

[INFO] Found 5 possible jdks: [/usr/lib/jvm/java-21-openjdk, /usr/lib/jvm/java-11-openjdk, /usr/lib/jvm/java-24-openjdk, /usr/lib/jvm/java-17-openjdk, /usr/lib/jvm/java-8-openjdk]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.884 s
[INFO] Finished at: 2025-06-18T13:41:51+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:select-jdk-toolchain (default) on project webserver: Cannot find matching toolchain definitions for the following toolchain types:{runtime.version=8}
[ERROR] Define the required toolchains in your ~/.m2/toolchains.xml file.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Activity

  1. jafarre-bi commented on Jul 2, 2025

    @jafarre-bi

    I don't think the runtime version is what you really want.
    I suggest replacing the <runtimeVersion/> config parameter with <version>[8,9)</version>, or simply defining the property <toolchain.jdk.version>[8,9)</toolchain.jdk.version> and removing the entire config section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions