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

被折叠的 条评论
为什么被折叠?



