记录一次 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>
 第二个是之前的子模块存在相互依赖,需要把相互依赖的版本也同意修改下才行
posted @ 2023-11-20 15:26  Doyourself!  阅读(285)  评论(0编辑  收藏  举报