理解maven的parent标签里面的relativePath
经常看到用Spring Initializr建立spring boot项目,生成的pom.xml包含如下parent:
①
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.2</version> <relativePath/> <!-- lookup parent from repository --> </parent>
也会看到一些maven module项目包含下面relativePath形式:
②
<parent>
<artifactId>admin</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
也有不写relativePath的,直接如下:
③
<parent>
<artifactId>admin</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
参考官方文档发现,relativePath是与从哪里继承相关联的,默认③什么都不写等同于②,像①那种是不依赖本地parent pom,直接从reposity拉取,
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.
寻找parent pom优先级:本地项目>文件系统>本地库>远程库,而springboot默认都是直接从远程库拉取的。
参考文档:
Understanding Maven’s “relativePath” Tag for a Parent POM:https://www.baeldung.com/maven-relativepath
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步