关于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
这个还用说吗,上面都找不到了,最后只能从远程仓库找啦,再找不到就报错给你看
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Spring BeanFactory和FactoryBean有哪些区别
这篇文章主要介绍了Spring BeanFactory 与 FactoryBean 的区别详情,BeanFactory 和 FactoryBean 的区别却是一个很重要的知识点,在本文中将结合源码进行分析讲解,需要的小伙伴可以参考一下2023-02-02
springboot应用中静态资源访问与接口请求冲突问题解决
这篇文章主要介绍了springboot应用中静态资源访问与接口请求冲突,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-06-06
使用RestTemplate调用RESTful API的代码示例
在开发 Web 应用程序时,调用 RESTful API 是一个常见的任务,本文将介绍如何使用 RestTemplate 调用 RESTful API,并提供示例代码,感兴趣的同学可以跟着小编一起来看看2023-06-06
SpringBoot使用Quartz无法注入Bean的问题及解决
这篇文章主要介绍了SpringBoot使用Quartz无法注入Bean的问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-11-11


最新评论