Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file

发布时间 2023-11-23 16:20:43作者: 金天黑日

转: https://blog.csdn.net/qq_26898033/article/details/128915500

1 错误信息

org/ springframework /boot / maven/BuildInfoMojo hasbeen copiled 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 52.0

 

2 原因

java 运行时的最新版本(类文件版本 61.0)编译的,该版本的 Java 运行时只识别 52.0 以下的类文件版本
根据 Spring Boot with spring version 2.5.7 fails repackage with jdk 1.8 这篇文章中下面的说法

 

目标org.springframework.boot:spring-boot-maven插件:3.0.0-M1:重新打包失败:由于API不兼容,无法在插件“org.springfframework.boot:spring-boot maven插件:3.0.0-M1”中加载mojo“重新打包”:org.codehaus.plexus.component.repository.exeption.ComponentLookupException:org/springframework/boot/maven/RepackageMojo已由较新版本的Java Runtime(类文件版本61.0),此版本的Java Runtime仅识别52.0以下的类文件版本

在你的 pom 中使用的“spring boot maven插件”版本。如果没指定spring-boot-maven-plugin 的版本,就会拿取最新的版本打包,但是目前高版本的为未必适合1.8的jdk,如果它确实是您想要用于 spring boot 项目的版本。
为了解决这个问题,就必须明确指定spring-boot-maven-plugin的版本

3 解决方法

  指定版本号

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <!--指定版本号 -->
    <version>2.7.1</version>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
                <goal>build-info</goal>
            </goals>
        </execution>
    </executions>
</plugin>