maven之發布項目到nexus【clean deploy命令】


原文:http://m.blog.csdn.net/article/details?id=49667971

 

 

 

當我們的項目開發完成以后,可能要進行發布(如果是獨立的項目,就不需要發布啦,如果是模塊項目,那么就要發布到nexus里,供其他開發人員下載調用。)

要想發布項目到nexus里,必須通過<distributionManagement>標簽來進行配置。在之前的文章中有介紹nexus的工廠類別,其中提到兩個:hosted里的Releases、Snapshots.

當我們發布項目到nexus里時,如果項目版本是x.x.x-Releases,則會發布到Releases工廠中;而項目版本是x.x.x-SNAPSHOTS則發布到Snapshots工廠中。

配置<distributionManagement>:

代碼:

 

<distributionManagement>
  	<repository>
  		<id>releasesId</id>
  		<name>Releases name</name>
  		<url>http://localhost:8081/nexus/content/repositories/releases/</url>
  	</repository>
  	<snapshotRepository>
  		<id>snapshots id</id>
  		<name>snapshots name</name>
  		<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  	</snapshotRepository>
  </distributionManagement>

右鍵項目 --> run as  ---> maven Build... --> 輸入clean deploy命令(一開始會下載一些依賴包,淡定.....)。

 

 

后面我們會看到如下的提示信息:

 

怎么來設置授權呢?

【1】:去到nexus管理界面 --- > 左側菜單欄“Security”  --> “Users” ,右側所列出的用戶中,只有deployment用戶才有發布項目到nexus的權限。

【2】:在setting.xml里使用<server>標簽進行授權。server里的id對應<distributionManagement>里設置的id。

流程是:當執行clean deploy命令進行發布時,首先會找到<distributionManagement>的配置,獲取配置信息。

然后如果setting.xml里有配置server,對比id值,如果匹配的上,就驗證server里的用戶是否擁有發布的權限,有權限就把項目發布到對應的倉庫里。

setting.xml中server標簽代碼:

 

<server>
      <id>releasesId</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>

	<server>
      <id>snapshotsid</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>

至此,發布的配置就完成了,執行clean deploy命令后,就會在nexus的Releases或Snapshots倉庫中找到發布的項目了。

 

 

 

 

如果我們不想把所有項目都發布到nexus的Releases或Snapshots倉庫中,而是想在nexus里能為每個項目開辟一個空間,存放每個項目自己發布上去的依賴包。

 

要實現這種效果,需要以下幾步操作:

(1)在nexus里為每個項目創建hosted類型的工廠(Releases或Snapshots兩種)

 

 

(2)在Securiy --> Privileges里添加Releases或Snapshots兩種工廠的特權(可以執行那些操作,如往工廠里發布,查看,刪除等特權)

 

 

(3)在Security --> Roles 里添加角色,為角色配置權限

 

(4)在Security --> Users 里添加用戶,為用戶設定角色

 

(5)在pom.xml里的 <distributionManagement>把url改為對應的工廠路徑,在setting里的server里設定對應的用戶密碼



執行clean deploy命令后:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM