Maven:Non-resolvable parent POM and ‘parent.relativePath‘ points at no local POM

本文讲述了如何解决Idea中Maven项目结构中,由于parent pom.xml配置问题导致的编译错误,重点在于正确设置`<relativePath>`。通过修改`mall-admin`模块的pom.xml,将`<relativePath/>`更改为`<relativePath>../pom.xml</relativePath>`,解决了依赖找不到的问题。

idea项目结构如下图,mall项目下有多个moudles,每个moudles内有各自的pom.xml文件

 

mall/pom.xml配置如下(注意关注parent部分)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.macro.mall</groupId>
    <artifactId>mall</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>mall-common</module>
        <module>mall-mbg</module>
        <module>mall-demo</module>
        <module>mall-admin</module>
        <module>mall-search</module>
        <module>mall-portal</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
</project>

mall/mall-admin/pom.xml配置如下(注意 relativePath 配置)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.macro.mall</groupId>
    <artifactId>mall-admin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>mall-admin</name>

    <parent>
        <groupId>com.macro.mall</groupId>
        <artifactId>mall</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath />
    </parent>
</project>

 

idea 使用maven编译报错如下

resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at no local POM

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.macro.mall:mall-admin:1.0-SNAPSHOT: Failure to find com.macro.mall:mall:pom:1.0-SNAPSHOT in http://maven.aliyun.com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at no local POM @ line 20, column 13
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.macro.mall:mall-admin:1.0-SNAPSHOT (D:\work\workspace\mall\mall-admin\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.macro.mall:mall-admin:1.0-SNAPSHOT: Failure to find com.macro.mall:mall:pom:1.0-SNAPSHOT in http://maven.aliyun.com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at no local POM @ line 20, column 13 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
Process finished with exit code 1

 

解决问题  

修改 mall/mall-admin/pom.xml 文件,替换 <relativePath />  为  <relativePath>../pom.xml</relativePath> 即可解决问题

 

问题原因:

modules内的pom.xml的parent依赖找不到所依赖的内容。

Maven项目中遇到Non-resolvable parent POM错误,提示无法找到`com.jd.onej:framework:pom:2.0-SNAPSHOT`工件且`parent.relativePath`指向错误本地POM,可参考以下解决方法: 1. **安装父项目**:多模块项目构建时,需先将parent项目install一回,之后子项目才可以运行`mvn compile`命令,否则就会报该异常。可在父项目的根目录下执行`mvn install`命令,将父项目安装到本地仓库,这样子项目就能从本地仓库找到父项目的POM文件了。 2. **检查`relativePath`配置**:在子项目的POM文件中,检查`<parent>`标签下的`<relativePath>`元素。若该元素指向的本地POM文件路径有误,Maven就无法找到父项目的POM文件。可将`<relativePath>`元素注释掉或设置为正确的相对路径,若父项目和子项目在同一目录下,可将`<relativePath>`设置为空,示例如下: ```xml <parent> <groupId>com.jd.onej</groupId> <artifactId>framework</artifactId> <version>2.0-SNAPSHOT</version> <!-- 将此处注释或设置为空 --> <relativePath/> </parent> ``` 3. **检查Maven仓库**:确保本地Maven仓库中存在`com.jd.onej:framework:2.0-SNAPSHOT`的POM文件。可查看本地仓库路径下对应的目录,通常本地仓库路径为`~/.m2/repository`。若本地仓库中没有该文件,可尝试删除本地仓库中该项目的相关文件,然后重新执行`mvn clean install`命令。 4. **检查远程仓库配置**:确保Maven配置文件`settings.xml`或项目的POM文件中配置了正确的远程仓库,这样Maven才能从远程仓库下载缺失的工件。可在`settings.xml`或POM文件中添加或检查远程仓库配置,示例如下: ```xml <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> ``` 5. **检查网络连接**:确保网络连接正常,Maven可以访问远程仓库。若网络存在问题,Maven将无法下载缺失的工件。可尝试访问远程仓库的URL,确保网络连接正常。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值