關(guān)于Maven parent.relativePath說明
Maven parent.relativePath說明
關(guān)于Maven非?;A(chǔ)的問題
Maven parent.relativePath 的意思,很多人網(wǎng)上搜索 類似下面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>
網(wǎng)上大多數(shù)回到如下:
- 設(shè)定一個(gè)空值將始終從倉庫中獲取,不從本地路徑獲取,如<relativePath />
- Maven parent.relativePath
- 默認(rèn)值為../pom.xml
- 查找順序:relativePath元素中的地址–本地倉庫–遠(yuǎn)程倉庫
部分 Java 菜鳥或是一部分老鳥竟然也懵
答案第一行 :
設(shè)定一個(gè)空值將始終從倉庫中獲取,不從本地路徑獲取,如<relativePath />
然后又開始問 : 倉庫 是哪一個(gè)倉庫 ???
我就納悶了搜什么百度,自己測(cè)試一下不就好了嗎,另外直接點(diǎn)擊進(jìn)去看原生說明啊,下面是 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>讀一讀英文,不行字典翻譯翻譯,然后自己做下實(shí)驗(yàn) 得出如下結(jié)論:
- relativePath 是Maven為了尋找父模塊pom.xml所額外增加的一個(gè)尋找路徑
- relativePath 默認(rèn)值為 …/pom.xml
Maven尋找父模塊pom.xml的順序
如下:
(1) first in the reactor of currently building projects
這里一個(gè)maven概念 反應(yīng)堆(reactor ),意思就是先從工程里面有依賴相關(guān)的模塊中找你引入的parent 的pom.xml,
(2) then in this location on the filesystem
然后從 你定義的 <relativePath > 路徑中找,當(dāng)然你如果只是 / 即空值,則跳過該步驟,默認(rèn)值 ../pom.xml 則是從上級(jí)目錄中找啦。
(3) then the local repository
這個(gè)就不說了,如果 (1) (2) 步驟沒有則從 本地倉庫找啦。
(4) and lastly in the remote repo
這個(gè)還用說嗎,上面都找不到了,最后只能從遠(yuǎn)程倉庫找啦,再找不到就報(bào)錯(cuò)給你看
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring BeanFactory和FactoryBean有哪些區(qū)別
這篇文章主要介紹了Spring BeanFactory 與 FactoryBean 的區(qū)別詳情,BeanFactory 和 FactoryBean 的區(qū)別卻是一個(gè)很重要的知識(shí)點(diǎn),在本文中將結(jié)合源碼進(jìn)行分析講解,需要的小伙伴可以參考一下2023-02-02
Java與Scala創(chuàng)建List與Map的實(shí)現(xiàn)方式
這篇文章主要介紹了Java與Scala創(chuàng)建List與Map的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10
淺談Java中BIO、NIO和AIO的區(qū)別和應(yīng)用場(chǎng)景
這篇文章主要介紹了Java中BIO、NIO和AIO的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
springboot應(yīng)用中靜態(tài)資源訪問與接口請(qǐng)求沖突問題解決
這篇文章主要介紹了springboot應(yīng)用中靜態(tài)資源訪問與接口請(qǐng)求沖突,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06
使用RestTemplate調(diào)用RESTful?API的代碼示例
在開發(fā)?Web?應(yīng)用程序時(shí),調(diào)用?RESTful?API?是一個(gè)常見的任務(wù),本文將介紹如何使用?RestTemplate?調(diào)用?RESTful?API,并提供示例代碼,感興趣的同學(xué)可以跟著小編一起來看看2023-06-06
微信小程序獲取手機(jī)號(hào),后端JAVA解密流程代碼
這篇文章主要介紹了微信小程序獲取手機(jī)號(hào),后端JAVA解密流程的代碼,幫助大家更好的利用Java開發(fā),感興趣的朋友可以了解下2020-09-09
SpringBoot使用Quartz無法注入Bean的問題及解決
這篇文章主要介紹了SpringBoot使用Quartz無法注入Bean的問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11

