spring-boot-maven-plugin未指定版本导致的编译错误

Posted 阿拉的梦想

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-boot-maven-plugin未指定版本导致的编译错误相关的知识,希望对你有一定的参考价值。

spring-boot-maven-plugin未指定版本导致的编译错误

报错
springboot应用在使用maven编译时会报如下错误:

Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-M2:repackage (default) on project mis: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-M2:repackage failed: Unable to load the mojo 'repackage' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.0-M2' 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 52.0
Caused by: java.lang.UnsupportedClassVersionError: 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 52.0

原因
原因是maven在编译打包过程中没有指定spring-boot-maven-plugin的版本,默认会从nexus仓库中拉取最新的打包插件版本,而最新的3.0.0版本不被jdk8支持,无法执行编译。

解决方案
需要用户在pom.xml文件中手动指定spring-boot-maven-plugin该插件的打包版本。

如:
加上版本<version>2.2.6.RELEASE</version>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.6.RELEASE</version>
                <configuration>
                    <finalName>$project.artifactId</finalName>
                    <mainClass>com.xxl.job.admin.XxlJobAdminApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

以上是关于spring-boot-maven-plugin未指定版本导致的编译错误的主要内容,如果未能解决你的问题,请参考以下文章

`spring-boot-maven-plugin` 和 `maven-compiler-plugin` 有啥区别?

spring-boot-maven-plugin插件作用

spring-boot-maven-plugin:build-image 失败并出现 400 Bad Request

spring-boot-maven-plugin:[unknown-version]

spring-boot-maven-plugin 安装本地jar 包

使用spring-boot-maven-plugin打包