1. 程式人生 > >Maven 私服搭建和使用

Maven 私服搭建和使用

一、下載安裝

1. 私服下載地址  https://www.sonatype.com/download-oss-sonatype

2.下載完成後解壓任意目錄,我的是D:\soft\nexus2\nexus-2.14.8-01

3.安裝

 在D:\soft\nexus2\nexus-2.14.8-01\bin\jsw\windows-x86-64下找到install-nexus 執行安裝成為windows服務

,安裝執行完之後執行start-nexus 啟動檔案

4.訪問你的本地私服地址:http://localhost:8081/nexus/

使用者名稱密碼 預設是:admin admin123

5.點選login進行登入


二、配置倉庫

6.點選左邊Repositories,可以看到一系列倉庫型別,我們一般使用3個,分別是Releases,Snapshots和3rdparty。這3個倉庫風別是裝穩定版,開發版和第三方jar包 。

7、開啟遠端索引

分別選擇type為proxy的三個庫Apache Snapshots、Central、Codehaus Snapshots

將Download Remote Indexes設定為true

在Apache Snapshots,Codehaus Snapshots和Central這三個倉庫上分別右鍵,選擇Repari Index


只有Central庫下載索引檔案成功,另兩個中央庫是Not published狀態

8、health check

點選綠色的analyze


點選YES。

三、maven配置檔案的配置

9.mvn直接釋出到私服上面來

 在settings檔案的servers節點下加入,這是配置私服的密碼和倉庫,配合pom檔案中的倉庫地址就構成了完成的訪問私服的要素,帳號和密碼之所以在settings中設定,是由於settings檔案是本地的,而pom.xml檔案是公共的,不安全,所以放在settings中:


<server>

      <id>nexus-releases</id>

      <username>admin</username>

      <password>admin123</password>

    </server>

     <server>

        <id>nexus-snapshots</id>

        <username>admin</username>

       <password>admin123</password>

</server>

四、工程配置

10.其他工程引用私服地址

專案工程引用配置:http://127.0.0.1:8081/nexus/content/repositories/central/


<repositories>

  <repository>

    <id>my-maven</id>

    <name>My Maven</name>

    <url>http://127.0.0.1:8081/nexus/content/repositories/central/</url>

    <releases>

      <enabled>true</enabled>

    </releases>

    <snapshots>

      <enabled>true</enabled>

    </snapshots>

  </repository>

</repositories>

檢視一下私服提供的jar


11.對外提供服務的組配置