I have a Jenkins pipeline with JAVA_HOME pointing at Java 11, and Maven Toolchain pointing to Java 17. It works fine with Java 17 code and Spring Boot 2.7, but when I try to upgrade to Spring Boot 3.0.1, Maven fails to spring-boot-maven-plugin due to Java versions mismatch. Here is a log that confirms Java 17 toolchain:
15:11:29 [INFO] --- maven-toolchains-plugin:3.1.0:toolchain (default) @ services-parent ---
15:11:29 [INFO] Required toolchain: jdk [ vendor='aws' version='17' ]
15:11:29 [INFO] Found matching toolchain for type jdk: JDK[/usr/lib/jvm/java-17-amazon-corretto.x86_64]
and here is the error:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:repackage (default) on project services-parent: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:repackage failed: Unable to load the mojo 'repackage' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.1' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/RepackageMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Looks like default Java 11 is used, though the plugin supports toolchain https://github.com/spring-projects/spring-boot/issues/18686
Comment From: wilkinsona
Spring Boot 2.x has a Java baseline of 8. This allowed Maven (or Gradle) to use Java 8. Spring Boot 3.x has a Java baseline of 17. This means that Maven (or Gradle) must use Java 17 to be able to load Boot's build plugins. Note that the issue that you have referenced and its accompanying PR added Toolchain support to spring-boot:run which has no effect on the behavior of repackaging.