關于Maven我應該知道的事
這里不是入門指南, 而是一些個人使用遇到的問題參考
一、環境
Maven 版本JDK要求
| Maven | Java |
|---|---|
| 3.3 - 3.6 | 7 |
| 3.2 | 6 |
| 3.0 - 3.1 | 5 |
- 1.0 - 2.x : End Of Life
官方文檔參考 : Maven Releases History
二、Maven Plugins
clean: 構建后清理compile: 編譯 Java 源代碼deploy: 將構建的構件部署到遠程存儲庫; 在集成或發布環境中完成,將最終包復制到遠程存儲庫中,以便與其他開發人員和項目共享install: 將構建的構件安裝到本地存儲庫中; 作為本地項目的依賴項。package: 使用已編譯的代碼,并將其打包成可部署格式,例如JAR。
官方文檔參考 : Maven Plugins
三、 setting.xml 加載順序
- 文件位置: 官網推薦是
USER_HOME/.m2/settings.xml, 想想也是, 這樣升級 Maven 時就不用擔心配置文件被覆蓋了.- 全局配置: ${M2_HOME}/conf/settings.xml
- 用戶配置: user.home/.m2/settings.xml
- 優先級 :
pom.xml>user settings>global settings- 應用運行時, 會合并這些配置內容, 如果重復, 則高優先級覆蓋低優先級
四、mirror 和 repository
如果遇到配置了mirrors 還是不能從鏡像中下載依賴包就要考慮這兩者之間的區別聯系了
settings.xml
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
| 這是用于從遠程存儲庫下載工件的鏡像列表。
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
| 它的工作方式是這樣的:POM可以聲明一個存儲庫以用于解決某些工件。
| 但是,此存儲庫有時可能會遇到流量大的問題,因此人們已經鏡像
| 它到幾個地方。
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
| 該存儲庫定義將具有唯一的ID,因此我們可以為此創建一個鏡像引用
| 存儲庫,用作備用下載站點。 鏡像站點將是首選該存儲庫的服務器。
|-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
| 指定要使用的存儲庫鏡像站點而不是給定的存儲庫。 該存儲庫
| 此鏡像服務的ID與該鏡像的mirrorOf元素匹配。 使用ID
| 用于繼承和直接查找目的,并且在整個鏡像集中必須唯一。
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors
pom.xml
<project>
...
<repositories>
<repository>
<id>my-internal-site</id>
<url>http://myserver/repo</url>
</repository>
</repositories>
...
</project>
重點
setting.xml中的<mirrorOf>要與pom.xml文件中的<repository?的id相對應;- 如果設置
<mirrorOf>*</mirrorOf>則會覆蓋其后的<mirror>, 所以一般會將<mirrorOf>*</mirrorOf>的鏡像配置放在<mirrors>的最后
參考文章: maven的mirror和repository加載順序
官方: Guide to Mirror Settings
官方: Settings Reference
官方: POM Reference
五、文獻資料
官方文檔里面幾乎可以找到你想要的內容
- 官方 文獻資料索引
- 官方 Maven 入門指南
作者:小鳴的微筆記
出處:52liming.cnblogs.com
轉載:文章可以轉載,但是請標注原文鏈接
原文:http://www.rzrgm.cn/52liming/p/12834485.html

浙公網安備 33010602011771號