理解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

 

相关文章

前言 此种方式已过时,不再推荐,当下推荐方式:自我救赎 →...
前言 项目中用到了maven,而且用到的内容不像利用maven/ecli...
开心一刻 今天去幼儿园接小侄女,路上聊起了天 小侄女:小叔...
本篇文章和大家了解一下怎么搭建maven私有仓库。有一定的参考...
今天小编给大家分享的是如何解决Maven依赖冲突,相信很多人都...
这篇文章主要介绍了Maven仓库分类的优先级是什么的相关知识,...