【Maven】maven私服Nexus安裝以及配置
運行環境:
Centos 7,jdk1.8
一、Nexus服務安裝
1)配置JDK
Nexus運行依賴JDK環境,需求提前在系統中配置jdk。下面 jdk1.8 Linux下載地址:
鏈接:https://pan.baidu.com/s/17t-S3LDjiFOHFto7tiEmsw
提取碼:yysm
profile文件配置:
export JAVA_HOME=/usr/local/src/jdk1.8.0_73
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
2)下載Nexus
Nexus官網地址:https://www.sonatype.com/nexus-repository-oss
選擇需要的下載的版本,
# nexus-3.19.1-01(Windows、Linux、Mac)
鏈接:https://pan.baidu.com/s/1LPZN_CMh7_SHdT_MnqxRvA
提取碼:hacg
3)解壓 nexus-3.19.1-01-unix.tar.gz
tar -zxvf nexus-3.19.1-01-unix.tar.gz
解壓后會有兩個文件,以當前3.19版本為例:
nexus-3.19.1-01 #服務目錄
sonatype-work #私有庫目錄
4)配置
vim nexus-3.19.1-01/etc/nexus-default.properties
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
##端口號
application-port=18081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
## 私有庫目錄指向,sonatype-work,一般默認不做修改
nexus-context-path=/
# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
nexus-pro-feature
nexus.hazelcast.discovery.isEnabled=true
配置以root用戶啟動,
vim nexus-3.19.1-01/bin/nexus.rc
#run_as_user=""
run_as_user=root
5)啟動
.nexus-3.19.1-01/bin/nexus start #啟動
.nexus-3.19.1-01/bin/nexus stop #停止
.nexus-3.19.1-01/bin/nexus restart #重啟
二、Nexus 服務的配置
1)訪問服務:http://IP:端口
2)首次登陸,根據提示,查找admin用戶的密碼,登陸並修改。
cat /data/software/sonatype-work/nexus3/admin.password
3)倉庫說明
(1)默認倉庫說明:
maven-central:maven 中央庫,默認從 https://repo1.maven.org/maven2/ 拉取 jar
maven-releases:私庫發行版 jar,初次安裝請將 Deployment policy 設置為 Allow redeploy
maven-snapshots:私庫快照(調試版本)jar
maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地 maven 基礎配置 settings.xml 或項目 pom.xml 中使用
(2)倉庫類型說明:
group:這是一個倉庫聚合的概念,用戶倉庫地址選擇 Group 的地址,即可訪問 Group 中配置的,用於方便開發人員自己設定的倉庫。maven-public 就是一個 Group 類型的倉庫,內部設置了多個倉庫,訪問順序取決於配置順序,3.x 默認為 Releases、Snapshots、Central,當然你也可以自己設置。
hosted:私有倉庫,內部項目的發布倉庫,專門用來存儲我們自己生成的 jar 文件
snapshots:本地項目的快照倉庫
releases: 本地項目發布的正式版本
proxy:代理類型,從遠程中央倉庫中尋找數據的倉庫(可以點擊對應的倉庫的 Configuration 頁簽下 Remote Storage 屬性的值即被代理的遠程倉庫的路徑),如可配置阿里雲 maven 倉庫
central:中央倉庫
4)添加阿里雲服務
【Create repository】->【 maven2(proxy)】
5)編輯 maven-public
編輯maven-public,並將剛才新增的aliyun-repository的優先級調高到第一
三、Maven使用私服配置
1)設置 settings.xml
全局共享
<mirrors>
<mirror>
<id>nexus</id>
<name>nexus maven</name>
<mirrorOf>*</mirrorOf>
<url>http://nexus.local:18081/repository/maven-public/</url>
</mirror>
</mirrors>
2)通過 pom.xml 文件配置,項目獨享模式
<repositories>
<repository>
<id>maven-nexus</id>
<name>maven-nexus</name>
<url>http://nexus.local:18081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Maven 配置使用私服(發布依賴)
1)設置 settings.xml
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>password</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
2)設置 pom.xml 文件中加入 distributionManagement 節點:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://nexus.local:18081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://nexus.local:18081/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>