maven pom 配置 學習筆記(二)之搭建nexus私服


一、安裝

1、從網上下載nexus軟件
https://www.sonatype.com/download-oss-sonatype  下載Nexus Repository Manager OSS軟件包
目前我使用的是3.0的版本,下面均是以安裝3.0的版本位例子
2、將下載下來的nexus-3.13.0-01-win64.zip解壓縮到目標路徑,官網建議windows不要放在Program files 下,那么本人放在D:/develop下面
3、
(1) 未注冊成系統服務,直接運行:
  a)進入bin目錄,運行cmd 命令 :nexus.exe /run 此時運行私有倉庫;linux版本可以執行:nexus /run
  b)按ctrl-c可以停止運行私服;
(2) 注冊成系統服務(需要確保jdk已經在系統中安裝過):
  a) 進入bin目錄,運行cmd:nexus.exe /install  此時會安裝私有倉庫;
  b) 安裝完成之后,默認訪問端口未8081,上下文為 /
  c) 進入頁面之后,直接登錄,賬號:admin  admin123
  d) 在訪問的時候,請使用ip訪問

4、關於Nexus Repository Manager 更多介紹 可參考網址:https://help.sonatype.com

二、配置

    按照以上的方法搭建好私服之后,此時需要對私服里面的內容進行配置,用戶通用瀏覽器(http://127.0.0.1:8001/)訪問私服。

1、以管理員身份登入私服

    在首頁的右上角點擊"Sign In" 進入登入頁面,賬號為:admin 密碼為:admin123;

2、配置代理倉庫

    本地maven(已安裝Maven軟件)setting.xml 中在沒有私服的情況下,需要配置各種代理或鏡像(通過這些將需要的第三方提供的jar包下載到本地倉庫供maven工程直接引用)。但是由於網速原因或在不同電腦項目中都需要連接網絡通過鏡像將所需jar包下載下來,一方面速度較慢,另一方面不好管理。因此需要私服,讓setting.xml直接配置私服的倉庫地址即可。

(1) 在私服中配置各種市面上常見的倉庫地址(增加新的代理源)

  • 設置名稱和URL

Cache統一設置為200天 288000

  • 逐個增加常用代理
1. aliyun
http://maven.aliyun.com/nexus/content/groups/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安裝后自帶,僅需設置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/
11. spring-snapshots
https://repo.spring.io/snapshot
//在配置這個代理源的時候,Version pollcy 要設置成 Snapshot,Layout pollcy 要設置成 Permissive.
12. spring-milestones
https://repo.spring.io/milestone

再次強調,在

How long (in minutes) to cache metadata before rechecking the remote repository.處

統一設置為

288000 即200天,當然可以設置為更長的時間

設置maven-public

  • 將這些代理加入Group

  • 設置私用倉庫可重復發布

  Nexus安裝后自帶maven-releases,maven-snapshots兩個倉庫,用於將生成的jar包發布在這兩個倉庫中,在實際開發中需要將maven-releases設置為可以重復發布。

  maven-releases

  

  注:maven-snapshots缺省是可以重新部署的。

(2) 在maven的安裝路徑下conf/Setting.xml中配置如下內容:

<settings>
  <pluginGroups>  
     <pluginGroup>org.sonatype.plugins</pluginGroup>  
  </pluginGroups> 
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
  <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
</settings>

(3) 測試

    將settings.xml中記錄的maven倉庫地址中的之前下載下來的jar包全部刪除。在maven 工程右鍵 Maven ---> update product,在出來的彈出框中選擇 "force update of snapshorts/releases",重新下載所需依賴的jar包即可。

 

PS:私服配置的內容參考了:https://www.cnblogs.com/fanzhenyong/p/7709434.html


免責聲明!

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



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