关于Maven parent.relativePath说明
Maven parent.relativePath说明
关于Maven非常基础的问题
Maven parent.relativePath 的意思,很多人网上搜索 类似下面pom.xml中的问题 ,文件中的
<relativePath /> <!-- lookup parent from repository -->
是什么意思?
<parent>
<groupId>com.middol</groupId>
<artifactId>webbase-dependency-management</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
网上大多数回到如下:
- 设定一个空值将始终从仓库中获取,不从本地路径获取,如<relativePath />
- Maven parent.relativePath
- 默认值为../pom.xml
- 查找顺序:relativePath元素中的地址–本地仓库–远程仓库
部分 Java 菜鸟或是一部分老鸟竟然也懵
答案第一行 :
设定一个空值将始终从仓库中获取,不从本地路径获取,如<relativePath />
然后又开始问 : 仓库 是哪一个仓库 !?
我就纳闷了搜什么百度,自己测试一下不就好了吗,另外直接点击进去看原生说明啊,下面是 xml 原生英文解释:
<xs:element name="relativePath" minOccurs="0" type="xs:string" default="../pom.xml">
<xs:annotation>
<xs:documentation source="version">4.0.0</xs:documentation>
<xs:documentation source="description">
The relative path of the parent <code>pom.xml</code> file within the check out.
The default value is <code>../pom.xml</code>.
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.
<code>relativePath</code> 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.
</xs:documentation>
</xs:annotation>
</xs:element>读一读英文,不行字典翻译翻译,然后自己做下实验 得出如下结论:
- relativePath 是Maven为了寻找父模块pom.xml所额外增加的一个寻找路径
- relativePath 默认值为 …/pom.xml
Maven寻找父模块pom.xml的顺序
如下:
(1) first in the reactor of currently building projects
这里一个maven概念 反应堆(reactor ),意思就是先从工程里面有依赖相关的模块中找你引入的parent 的pom.xml,
(2) then in this location on the filesystem
然后从 你定义的 <relativePath > 路径中找,当然你如果只是 / 即空值,则跳过该步骤,默认值 ../pom.xml 则是从上级目录中找啦。
(3) then the local repository
这个就不说了,如果 (1) (2) 步骤没有则从 本地仓库找啦。
(4) and lastly in the remote repo
这个还用说吗,上面都找不到了,最后只能从远程仓库找啦,再找不到就报错给你看
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
MyBatis-Plus找不到Mapper.xml文件的几种解决方法
mybatis-plus今天遇到一个问题,就是mybatis 没有读取到mapper.xml 文件,所以下面这篇文章主要给大家介绍了关于MyBatis-Plus找不到Mapper.xml文件的几种解决方法,需要的朋友可以参考下2022-06-06
解决springboot中mongodb不启动及Dao不能被扫描到的问题
这篇文章主要介绍了解决springboot中mongodb不启动及Dao不能被扫描到的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-05-05
SpringBoot详细分析自动装配原理并实现starter
相对于传统意义上的Spring项目,SpringBoot具有开箱即用,简化配置,内置Tomcat等等等等一系列的特点。在这些特点中,最重要的两条就是约定优于配置和自动装配2022-07-07
SpringBoot中@MessageMapping注解的原理及使用详解
这篇文章主要介绍了SpringBoot中@MessageMapping注解的原理及使用详解,@MessageMapping注解是Spring Boot提供的一个重要的注解之一,它可以帮助我们处理WebSocket消息,需要的朋友可以参考下2023-07-07


最新评论