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>

问题解决。

相关推荐
学长毕业设计7 小时前
基于SpringBoot的公益基金管理系统(源码+文档+讲解视频)
java·spring boot·后端
独泪了无痕10 小时前
SpringBoot Event事件机制,轻松实现业务解耦
spring boot·后端·spring
悲且狂11 小时前
SpringBoot项目改造注意事项(旧项目框架复用)
java·spring boot·后端
SQL-First布道者16 小时前
⚡Spring JDBC 完整体系 · 第 10 集 · 手搓 `BaseCondition`
java·spring boot·后端·spring·mybatis·spring jdbc
2601_9620746816 小时前
Spring Boot的无缝衔接:深入解析与实践
数据库·spring boot·后端
南城以南溫暖如初14717 小时前
社交裂变商城系统设计与实战开发指南
java·spring boot·mysql·vue·mybatis
xiaoqiMikko17 小时前
Spring 官方给 5.3 线开了三个修复版,Maven Central 上一个都没有
java·spring boot
南城以南溫暖如初14717 小时前
分享返现商城系统开发实战:技术架构与运营经验指南
java·spring boot·mysql·架构·vue·mybatis
vipxieliang17 小时前
Java切面编程(AOP)详解:从核心概念到实战应用
java·spring boot
.Hypocritical.17 小时前
SpringBoot 各版本 Profile 多环境配置完整对比(2.x/ 2.4+ / 3.x/4.x
java·spring boot·后端