spring-boot-maven-plugin未指定版本導(dǎo)致的編譯錯誤問題
spring-boot-maven-plugin未指定版本導(dǎo)致的編譯錯誤
報錯
springboot應(yīng)用在使用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的版本,默認(rèn)會從nexus倉庫中拉取最新的打包插件版本,而最新的3.0.0版本不被jdk8支持,無法執(zhí)行編譯。
解決方案
需要用戶在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 構(gòu)建找不到
問題描述
本地編譯打包maven項(xiàng)目時,報spring-boot-maven-plugin 構(gòu)建找不到的錯誤。昨天還好好的,本地代碼里的pom文件沒有做任何改動。
pom.xml中有一段下面的配置:(已去掉項(xiàng)目信息)
<plugin> ?? ?<groupId>org.springframework.boot</groupId> ?? ?<artifactId>spring-boot-maven-plugin</artifactId> ?? ?<executions> ?? ??? ?<execution> ?? ??? ??? ?<goals> ?? ??? ??? ??? ?<goal>repackage</goal> ?? ??? ??? ?</goals> ?? ??? ?</execution> ?? ?</executions> ?? ?<configuration> ?? ??? ?<classifier>boot</classifier> ?? ??? ?<mainClass>...</mainClass> ?? ?</configuration> </plugin>
關(guān)鍵錯誤信息如下:
spring-boot-maven-plugin-2.3.1.RELEASE.jar找不到。
分析
- 去本地倉庫,檢查是否有該jar包
- ${user.home}/.m2
- 去遠(yuǎn)程倉庫查看,檢查是否有該版本的jar包
通過對比,發(fā)現(xiàn)遠(yuǎn)程倉庫里有了最新版本的路徑,但是里面確沒有jar包。
解決
通過分析,可以總結(jié)如下:
spring-boot-maven-plugin沒有設(shè)置version,它會先去遠(yuǎn)程倉庫找最新的版本,然后download到本地,然后完成maven操作等。但是遠(yuǎn)程倉庫里沒有相應(yīng)的jar包,導(dǎo)致執(zhí)行maven編譯出錯。因?yàn)檫h(yuǎn)程倉庫里已經(jīng)有了最新版本的路徑,它就不會使用已經(jīng)存在的版本。
解決:
給spring-boot-maven-plugin指定具體的version,如下設(shè)置:
<plugin> ?? ?<groupId>org.springframework.boot</groupId> ?? ?<artifactId>spring-boot-maven-plugin</artifactId> ?? ?<version>2.3.0.RELEASE</version> ?? ?<executions> ?? ??? ?<execution> ?? ??? ??? ?<goals> ?? ??? ??? ??? ?<goal>repackage</goal> ?? ??? ??? ?</goals> ?? ??? ?</execution> ?? ?</executions> ?? ?<configuration> ?? ??? ?<classifier>boot</classifier> ?? ??? ?<mainClass>...</mainClass> ?? ?</configuration> </plugin>
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java實(shí)現(xiàn)鏈表數(shù)據(jù)結(jié)構(gòu)的方法
這篇文章主要介紹了Java實(shí)現(xiàn)鏈表數(shù)據(jù)結(jié)構(gòu)的相關(guān)資料,每一個鏈表都包含多個節(jié)點(diǎn),節(jié)點(diǎn)又包含兩個部分,一個是數(shù)據(jù)域(儲存節(jié)點(diǎn)含有的信息),一個是引用域(儲存下一個節(jié)點(diǎn)或者上一個節(jié)點(diǎn)的地址),需要的朋友可以參考下2022-01-01SpringBoot整合RabbitMQ實(shí)現(xiàn)流量消峰
RabbitMQ 即一個消息隊(duì)列,主要是用來實(shí)現(xiàn)應(yīng)用程序的異步和解耦,同時也能起到消息緩沖,消息分發(fā)的作用,消息中間件在互聯(lián)網(wǎng)公司的使用中越來越多,本文給大家介紹了SpringBoot整合RabbitMQ實(shí)現(xiàn)流量消峰,需要的朋友可以參考下2024-12-12Spring MVC過濾器-登錄過濾的代碼實(shí)現(xiàn)
本篇文章主要介紹了Spring MVC過濾器-登錄過濾,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧。2017-01-01Java使用hutool實(shí)現(xiàn)文件大小的友好輸出
這篇文章主要為大家詳細(xì)介紹了Java如何使用hutool實(shí)現(xiàn)文件大小的友好輸出,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價值,感興趣的小伙伴可以了解下2023-11-11Java 替換字符串右側(cè)出現(xiàn)的第一個子串方式
這篇文章主要介紹了Java 替換字符串右側(cè)出現(xiàn)的第一個子串方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08SpringBoot中的Condition包下常用條件依賴注解案例介紹
這篇文章主要介紹了SpringBoot中的Condition包下常用條件依賴注解案例,文章基于Java的相關(guān)資料展開主題詳細(xì)內(nèi)容,需要的小伙伴可以參考一下2022-04-04