本文轉載自滄海一屌絲的博客
https://blog.csdn.net/qq_31924435/article/details/53745811
mvn install 會將項目生成的構件安裝到本地Maven倉庫,
mvn deploy 用來將項目生成的構件分發到遠程Maven倉庫。
<project> ... <distributionManagement> //分發管理 <repository> <id>nexus-releases</id> //關系 releases-發布、版本 <name>Nexus Release Repository</name> <url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> //快照倉庫 <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> ... </project>
Maven區別對待release版本的構件和snapshot版本的構件,snapshot為開發過程中的版本,實時,但不穩定,release版本則比較穩定。Maven會根據你項目的版本來判斷將構件分發到哪個倉庫。
一般來說,分發構件到遠程倉庫需要認證,如果你沒有配置任何認證信息,你往往會得到401錯誤。這個時候,如下在settings.xml中配置認證信息:
<settings> ... <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> ... </settings>
需要注意的是,settings.xml中server元素下id的值必須與POM中repository或snapshotRepository下id的值完全一致。將認證信息放到settings下而非POM中,是因為POM往往是它人可見的,而settings.xml是本地的。
