maven的pom文件中<relativePath/>的作用

官方说明:The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, 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. This feature is only for enhancing the development in a local checkout of that project. Set the value to an empty string in case you want to disable the feature and always resolve the parent POM from the repositories.
简单总结一下:
· 如果没有指定,则默认就是会查找本地项目上一级路径(../pom.xml),如果指定了,则以指定的路径为准。在此基础下,Maven会首先在本地路径(文件系统)中查找,然后就是本地仓库,最后才是远程仓库。
· 如果显式地设置为空值(<relativePath/>或<relativePath></relativePath>)则先从本地仓库拉取,然后去远程仓库拉取

由此得出Maven的默认查找顺序是:文件系统 > 本地仓库 > 远程仓库

所以在

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.2.6.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository 直接从远程库拉取 -->
</parent>

中,因为为空,则Maven默认先从本地仓库拉取,然后去远程仓库拉取

<parent>
	<groupId>com.timqiu.gulimall</groupId>
	<artifactId>gulimall</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</parent><parent>
	<groupId>com.timqiu.gulimall</groupId>
	<artifactId>gulimall</artifactId>
	<version>0.0.1-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
</parent>

中,为上一级路径,则Maven的查找顺序为 文件系统 > 本地仓库 > 远程仓库

posted @   TimQiu  阅读(849)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示