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 @ 2023-04-18 19:14  TimQiu  阅读(974)  评论(0)    收藏  举报