Maven中錯(cuò)誤使用parent.relativePath導(dǎo)致構(gòu)建失敗問題
Maven中錯(cuò)誤使用parent.relativePath導(dǎo)致構(gòu)建失敗
搭建一個(gè)SpringBoot項(xiàng)目,Maven結(jié)構(gòu)為一個(gè)空的父模塊包含兩個(gè)子模塊
- 父模塊繼承
spring-boot-starter-parent
<!-- 部分內(nèi)容 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mos</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>consume</module>
<module>produce</module>
</modules>- 子模塊繼承父模塊
<!-- 部分內(nèi)容 -->
<parent>
<groupId>com.mos</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath/><!-- 注意這個(gè)標(biāo)簽 -->
</parent>
<artifactId>consume</artifactId>
<version>1.0.0</version>然后通過Maven構(gòu)建,報(bào)錯(cuò),提示遠(yuǎn)程/本地倉庫中都找不到 com.mos:parent 這個(gè)項(xiàng)目,本地創(chuàng)建的項(xiàng)目,也沒有安裝到本地倉庫,肯定兩邊都找不到啊。
但是以前也正常,為什么就這個(gè)項(xiàng)目突然出問題了,原因就出在子項(xiàng)目的 <relativePath/> 標(biāo)簽上,
官方對(duì)該標(biāo)簽解釋
Maven looks for the parent pom first in the reactor of currently building projects, then in this location on the filesystem, then the local repository, and lastly in the remote repo.
- Maven首先在當(dāng)前構(gòu)建項(xiàng)目的reactor中查找父pom,然后在文件系統(tǒng),然后是本地存儲(chǔ)庫,最后是遠(yuǎn)程repo。
for example when your structure is flat, or deeper without an intermediate parent pom. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM.
- 例如,當(dāng)您的結(jié)構(gòu)是平的,或者更深而沒有中間父pom時(shí)。但是,組ID、工件ID和版本仍然是必需的,并且必須與給定位置的文件匹配,否則它將恢復(fù)到POM的存儲(chǔ)庫。(即設(shè)定一個(gè)空值或給定位置不存在時(shí),將始終從倉庫中獲取,不從本地路徑獲取,如
<relativePath/>)
因?yàn)樽幽K都是用IDEA的SpringBoot模板構(gòu)建的,所以 pom.xml 里面都有 <relativePath/> 標(biāo)簽,去除即可。
- 或者手動(dòng)為其指明父pom
<relativePath>../pom.xml</relativePath>
問題解決。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java自定義注解實(shí)現(xiàn)前后臺(tái)參數(shù)校驗(yàn)的實(shí)例
下面小編就為大家?guī)硪黄猨ava自定義注解實(shí)現(xiàn)前后臺(tái)參數(shù)校驗(yàn)的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11
JAVA項(xiàng)目如何打包部署到Linux服務(wù)器上
本文詳細(xì)介紹了在服務(wù)器上部署環(huán)境包括JDK、MySQL、Tomcat的設(shè)置,以及使用Idea-Maven-SpringBoot進(jìn)行jar包打包部署的流程,內(nèi)容涵蓋了MySQL配置注意事項(xiàng)、pom.xml配置、打包命令等關(guān)鍵步驟,同時(shí),也提供了如何將jar包上傳到Linux服務(wù)器并運(yùn)行的具體方法2024-10-10
IDEA 2019.2.2配置Maven3.6.2打開Maven項(xiàng)目出現(xiàn) Unable to import Maven
這篇文章主要介紹了IDEA 2019.2.2配置Maven3.6.2打開Maven項(xiàng)目出現(xiàn) Unable to import Maven project的問題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
Java生成訂單號(hào)或唯一id的高并發(fā)方案(4種方法)
本文主要介紹了Java生成訂單號(hào)或唯一id的高并發(fā)方案,包括4種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-01-01
rocketmq的AclClientRPCHook權(quán)限控制使用技巧示例詳解
這篇文章主要為大家介紹了rocketmq的AclClientRPCHook使用技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
springboot整合ACTable生成數(shù)據(jù)庫表方式
ACTable是一個(gè)增強(qiáng)Mybatis的功能框架,支持SpringBoot和SpringMvc項(xiàng)目,通過配置model注解即可創(chuàng)建、修改表結(jié)構(gòu),并實(shí)現(xiàn)了共通的CRUD功能2025-02-02

