Maven中错误使用parent.relativePath导致构建失败

Maven中错误使用parent.relativePath导致构建失败

搭建一个SpringBoot项目,Maven结构为一个空的父模块包含两个子模块,父模块继承 spring-boot-starter-parent

xml 复制代码
 <!-- 部分内容 -->
 <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>

子模块继承父模块

xml 复制代码
 <!-- 部分内容 -->
 <parent>
     <groupId>com.mos</groupId>
     <artifactId>parent</artifactId>
     <version>1.0.0</version>
     <relativePath/><!-- 注意这个标签 -->
 </parent>
 ​
 <artifactId>consume</artifactId>
 <version>1.0.0</version>

然后通过Maven构建,报错,提示远程/本地仓库中都找不到 com.mos:parent 这个项目,本地创建的项目,也没有安装到本地仓库,肯定两边都找不到啊。

但是以前也正常,为什么就这个项目突然出问题了,原因就出在子项目的 <relativePath/> 标签上,官方对该标签解释如下:

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首先在当前构建项目的reactor中查找父pom,然后在文件系统,然后是本地存储库,最后是远程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.

例如,当您的结构是平的,或者更深而没有中间父pom时。但是,组ID、工件ID和版本仍然是必需的,并且必须与给定位置的文件匹配,否则它将恢复到POM的存储库。(即设定一个空值或给定位置不存在时,将始终从仓库中获取,不从本地路径获取,如 <relativePath/>

因为子模块都是用IDEA的SpringBoot模板构建的,所以 pom.xml 里面都有 <relativePath/> 标签,去除即可。

或者手动为其指明父pom

bash 复制代码
 <relativePath>../pom.xml</relativePath>

问题解决。

相关推荐
好好研究9 小时前
SpringBoot - yml配置文件
java·spring boot·spring
JH307312 小时前
SpringBoot自定义启动banner:给项目加个专属“开机画面”
java·spring boot·后端
猿小羽13 小时前
AI 学习与实战系列:Spring AI + MCP 深度实战——构建标准化、可扩展的智能 Agent 系统
java·spring boot·llm·agent·spring ai·mcp·model context protocol
Coder_Boy_15 小时前
基于SpringAI的在线考试系统-数据库设计核心业务方案
java·数据库·spring boot·ddd·tdd
风象南16 小时前
Spring Boot 定时任务多实例互斥执行
java·spring boot·后端
毕设源码-郭学长16 小时前
【开题答辩全过程】以 基于Springboot旅游景点管理系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端
Y_0317 小时前
SpringBoot+VUE3的图书管理系统
vue.js·spring boot·毕业设计·数据可视化
像少年啦飞驰点、17 小时前
零基础入门 Spring Boot:从‘Hello World’到可部署微服务的完整学习路径
java·spring boot·web开发·编程入门·后端教程
qq_124987075317 小时前
基于SpringBoot的闪电队篮球俱乐部管理系统的设计与开发(源码+论文+部署+安装)
java·数据库·spring boot·后端·spring·毕业设计·计算机毕业设计
a努力。17 小时前
中国邮政Java面试被问:MySQL的ICP(索引条件下推)优化原理
java·开发语言·数据仓库·面试·职场和发展·重构·maven