【From】 https://blog.csdn.net/qq250782929/article/details/51605965
Nexus Manager OSS 3.0 —Maven Repository
前言
網上基本搜不到 Nexus 3.0 版本以上的相關配置文檔,最近剛好在弄,就順便寫下來了,當作筆記。
nexus官方文檔
1.下載
下載地址:
http://www.sonatype.com/download-oss-sonatype
選擇對應的版本下載,本文章以nexus-3.0.0-03-win64.zip版本為例。(其他版本大同小異)
Nexus 3.xx 版本除了Maven以外還支持 Docker ,NuGet ,npm ,Bower 。有時間的可以嘗試一下。
2.解壓
將下載好的zip格式的解壓到指定目錄。(Windows用戶需注意目錄路徑不能含有中文,空格等字符)
3.執行
3.0版本:進入到nexus的bin目錄 nexus /start 執行
cd D:\nexus-3.0.0-03\bin
D:\nexus-3.0.0-03\bin>nexus /start
3.2版本:進入到nexus的bin目錄 nexus /start 執行
cd D:\nexus-3.0.0-03\bin
D:\nexus-3.0.0-03\bin>nexus.exe /run
默認應用地址是http://localhost:8081,若需要更改:
3.0版本:
打開 ..\nexus-3.0.0-03\etc\org.sonatype.nexus.cfg
修改端口: application-port
修改ip: application-host
3.2版本:
打開 ..\nexus\sonatype-work\nexus3\etc\nexus.properties
修改端口: application-port
修改ip: application-host
4.配置 Nexus
用瀏覽器打開 http://localhost:8081
點擊右上角Sign in 按鈕登錄。默認用戶名:admin,密碼:admin123
點擊齒輪狀配置按鈕,進入配置頁面:
進入Repository-Repositories
Repository的type屬性有:proxy,hosted,group三種。
proxy:即你可以設置代理,設置了代理之后,在你的nexus中找不到的依賴就會去配置的代理的地址中找
hosted:你可以上傳你自己的項目到這里面
group:它可以包含前面兩個,是一個聚合體。一般用來給客戶一個訪問nexus的統一地址。
簡單的說,就是你可以上傳私有的項目到hosted,以及配置proxy以獲取第三方的依賴(比如可以配置中央倉庫的地址)。前面兩個都弄好了之后,在通過group聚合給客戶提供統一的訪問地址
至於format,因為本文講的的 Maven Repository ,所以請選擇maven2;
系統默認就有以上幾個Repository。點擊maven-public 確保已經將 maven-central,maven-releases以及maven-snapshots都包含在里面。
maven-releases : 默認配置只能上傳 release版本的項目
maven-snapshots: 默認配置只能上傳 snapshots版本的項目
如有特殊要求,可以自己創建一個Version policy 為Mixed的Repository。
以上配置就能滿足一般需求了。
5.使用 mvn deploy 向 Nexus服務器 上傳項目
maven setting.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>E:/repository</localRepository>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>
localRepository:本地庫的地址
mirror:nexus地址
servers:nexus服務器登錄名和密碼
1.使用cmd上傳
mvn deploy:deploy-file -DgroupId=com.cxx -DartifactId=fu -Dversion=1.0.0 -Dpackaging=jar -Dfile=D:\gworkspace\work\cxx\fu\target\fu.jar -Durl=http://localhost:8081/repository/maven-releases/ -DrepositoryId=nexus -s D:\maven-3.2.1\conf\settings.xml
參數說明:
-D 傳入指定參數 分別對應pom中的 groupId,artifactId,version,packaging
file 本地jar的路徑
url Repository Url (請選擇對應release,snapshots或mixed的url)
repositoryId 對應setting.xml中server id
-s setting.xml的路徑(如果使用默認conf中的setting,則無需配置)
2.使用IDE上傳
項目中的pom文件添加
<distributionManagement>
<repository>
<id>nexus</id>
<name>maven-releases</name>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
id:對應setting.xml中server id
name:nexus Repository name
url:nexus Repository url
然后使用IDE自帶的Maven deploy就可以了。
然后就可以在nexus中看到你上傳的:
這樣你的maven項目就能引用你所上傳的項目了。