記錄一次 maven 子模塊相互依賴導致的父模塊無法動態升級的問題 'parent.relativePath' points at wrong local POM
項目里面使用的commons公共模塊,每次更改后之前都不會升級其版本號,導致當commons改動后,其他服務在不知道的情況下,會出現文件缺失。由于之前commons下面有12個公共子模塊,所以之前一直沒有升級commons模塊。為了方便,于是決定每次更改commons模塊后讓所有的子項目都跟著升級。
但是改造的過程中,出現了問題。
<groupId>com.gwm.marketing</groupId>
<artifactId>gwm-marketing-commons</artifactId>
<version>${commons.version}</version>
<packaging>pom</packaging>
<properties>
<commons.version>1.0.1-SNAPSHOT</commons.version>
</properties>
這個是我在父模塊中的定義,然后在子模塊中如下:
<parent>
<groupId>com.gwm.marketing</groupId>
<artifactId>gwm-marketing-commons</artifactId>
<version>${commons.version}</version>
</parent>
結果在編譯時候報錯如下:
[2023-11-20 15:03:03] [ERROR] The build could not read 12 projects -> [Help 1] [2023-11-20 15:03:03] [ERROR] [2023-11-20 15:03:03] [ERROR] The project com.gwm.marketing:gwm-marketing-cache:${commons.version} (/root/workspace/gwm-marketing-cache/pom.xml) has 1 error [2023-11-20 15:03:03] [ERROR] Non-resolvable parent POM for com.gwm.marketing:gwm-marketing-cache:${commons.version}: Could not find artifact com.gwm.marketing:gwm-marketing-commons:pom:${commons.version} in gwm-maven (https://gwmdc-maven.pkg.coding.net/repository/gwm-boot/gwm-maven) and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2] [2023-11-20 15:03:03] [ERROR] [2023-11-20 15:03:03] [ERROR] The project com.gwm.marketing:gwm-marketing-common:${commons.version} (/root/workspace/gwm-marketing-common/pom.xml) has 1 error [2023-11-20 15:03:03] [ERROR] Non-resolvable parent POM for com.gwm.marketing:gwm-marketing-common:${commons.version}: Failure to find com.gwm.marketing:gwm-marketing-commons:pom:${commons.version} in https://gwmdc-maven.pkg.coding.net/repository/gwm-boot/gwm-maven was cached in the local repository, resolution will not be reattempted until the update interval of gwm-maven has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2] [2023-11-20 15:03:03] [ERROR] [2023-11-20 15:03:03] [ERROR] The project com.gwm.marketing:gwm-marketing-feign:${commons.version} (/root/workspace/gwm-marketing-feign/pom.xml) has 1 error [2023-11-20 15:03:03] [ERROR] Non-resolvable parent POM for com.gwm.marketing:gwm-marketing-feign:${commons.version}: Failure to find com.gwm.marketing:gwm-marketing-commons:pom:${commons.version} in https://gwmdc-maven.pkg.coding.net/repository/gwm-boot/gwm-maven was cached in the local repository, resolution will not be reattempted until the update interval of gwm-maven has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 9, column 13 -> [Help 2]
12個子模塊,剛好對應 The build could not read 12 projects - ,由報錯信息可以知道,是因為 我在父模塊中定義的公共屬性 ${commons.version} 在子模塊中找不到,所有的子模塊我用的都是一個公共配置,這樣每次改動升級commons版本后,只需要父模塊升級一下,然后引入的地方對應改動下即可。思路是沒問題的,但是怎么就報錯了呢?
網上顯示搜索了下,參考(https://blog.csdn.net/q7w8e9r4/article/details/133639219、https://blog.csdn.net/rightkk/article/details/128856354) 發現是說 在子模塊配置中缺少
<relativePath></relativePath> 的配置,
于是我把所有的子模塊都加上這個,子模塊配置如下:
<parent>
<groupId>com.gwm.marketing</groupId>
<artifactId>gwm-marketing-commons</artifactId>
<version>${commons.version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
結果仍然是報錯。
這時候想了下,會不會是我子模塊中原來寫的 模塊有相互依賴是寫死的導致的,原來的12個子模塊中,歷史的原因,存在相互依賴的引用關系,之前的依賴都是寫死的,于是把原來寫死的 統一都改成 ${commons.version}。發現就可以了。。
另外我試下了:在子模塊中使用
<relativePath>../pom.xml</relativePath>
和
<relativePath>../../gwm-marketing-commons/pom.xml</relativePath> 的結果竟然是不一致,按照我的理解,.../../gwm-marketing-commons/pom.xml 和 直接使用../pom.xml應該都是一樣的才對,因為都是相對路徑,可是實際結果是 只有
<relativePath>../pom.xml</relativePath>
才可以。
總結下來,有兩個原因:首先是 缺少
<relativePath>../pom.xml</relativePath>
第二個是之前的子模塊存在相互依賴,需要把相互依賴的版本也同意修改下才行

浙公網安備 33010602011771號