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>

问题解决。

相关推荐
一 乐3 小时前
酒店预订|基于springboot + vue酒店预订系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·酒店预订系统
格鸰爱童话4 小时前
向AI学习项目技能(六)
java·人工智能·spring boot·python·学习
H_老邪4 小时前
spring boot 学习之路-1.0
spring boot·后端·学习
Flittly4 小时前
【SpringAIAlibaba新手村系列】(18)Agent 智能体与今日菜单应用
java·spring boot·agent
Andya_net5 小时前
Java | 基于 Feign 流式传输操作SFTP文件传输
java·开发语言·spring boot
成为大佬先秃头6 小时前
开放标准(RFC 7519):JSON Web Token (JWT)
spring boot·后端·json·jwt
不懂的浪漫8 小时前
# mqtt-plus 架构解析(八):Spring Boot 自动装配,这些零件是怎么被粘合起来的
spring boot·后端·物联网·mqtt·架构
却话巴山夜雨时i8 小时前
互联网大厂Java面试场景:Spring Boot、微服务与Redis实战解析
spring boot·redis·微服务·kafka·prometheus·java面试·电商场景
希望永不加班9 小时前
SpringBoot 配置绑定:@ConfigurationProperties
java·spring boot·后端·spring
indexsunny9 小时前
互联网大厂Java面试实战:Spring Boot、MyBatis与Kafka在电商场景中的应用
java·spring boot·面试·kafka·mybatis·电商·技术栈