1.最近接手了一个老项目,由于重启服务器,需要启动服务,但是发现再次部署Jenkis报错,不能重新部署报错,报错信息如下:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.5:repackage (default) on project XX-manager: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:3.0.5:repackage failed: Unable to load the mojo 'repackage' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.5' 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
ps:不涉及到Jenkis,如果是本地编译报错,也是这样解决处理。
2.原因
由于spring-boot-maven-plugin没有指定版本,Jenkis部署的时候自动获取最新版本,而最新版本的不兼容,导致的该问题,以下代码是历史代码:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.XXXX.XXXX</mainClass>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
3.解决办法
spring-boot-maven-plugin指定版本,查看了Jenkis的部署成功的日志,之前成功的获取的版本是“2.2.5.RELEASE”(可以根据需要尝试低版本的),将version设置为2.2.5.RELEASE就可以了。
Jenkis部署成功的日志:
[INFO] --- spring-boot-maven-plugin:2.2.5.RELEASE:repackage (default) @ XXXX ---
[INFO] Replacing main artifact with repackaged archive
修改的配置文件:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.5.RELEASE</version>
<configuration>
<mainClass>com.XXXX.XXXX</mainClass>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
这样问题就解决了,如果对您有帮助,记得点赞呀~