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>

问题解决。

相关推荐
麦兜*2 小时前
Spring Boot启动优化7板斧(延迟初始化、组件扫描精准打击、JVM参数调优):砍掉70%启动时间的魔鬼实践
java·jvm·spring boot·后端·spring·spring cloud·系统架构
KK溜了溜了3 小时前
JAVA-springboot 整合Redis
java·spring boot·redis
大只鹅3 小时前
解决 Spring Boot 对 Elasticsearch 字段没有小驼峰映射的问题
spring boot·后端·elasticsearch
天河归来3 小时前
使用idea创建springboot单体项目
java·spring boot·intellij-idea
IT_10243 小时前
Spring Boot项目开发实战销售管理系统——数据库设计!
java·开发语言·数据库·spring boot·后端·oracle
武昌库里写JAVA4 小时前
Oracle如何使用序列 Oracle序列使用教程
java·开发语言·spring boot·学习·课程设计
超级小忍5 小时前
Spring Boot 中常用的工具类库及其使用示例(完整版)
spring boot·后端
程序员张35 小时前
SQL分析与打印-p6spy组件
spring boot·sql·mybatis·mybatisplus·p6spy
CHENWENFEIc6 小时前
SpringBoot论坛系统安全测试实战报告
spring boot·后端·程序人生·spring·系统安全·安全测试
用户297994363797 小时前
maven的安装和配置
maven