四激才、基于nexus搭建企業(yè)級內(nèi)網(wǎng)私服
1苛败、nexus安裝
關(guān)于nexus的安裝啟動從官網(wǎng)http://nexus.sonatype.org/downloads/自行下載安裝即可
nexus的默認管理員賬號和密碼是:admin璃哟、admin123
2、nexus中的各種倉庫認識
hosted 宿主倉庫,一般把公司內(nèi)部的包發(fā)布在這個倉庫中來供其他項目組下載使用
proxy 代理倉庫惨驶,代理外部各種倉庫和中央倉庫的倉庫,最最常見的是阿里云鏡像倉庫配置在這里
3rd party某些無法直接獲取到的包敛助,如某些商業(yè)包比如oracle驅(qū)動粗卜,手動下載或?qū)氲竭@里
-
group 不是一個倉庫而是一個倉庫組
將以上各種倉庫配置成一個虛擬的倉庫組,本地項目依賴于該統(tǒng)一的倉庫組纳击,自動連接到需要依賴的不同倉庫续扔,主要有以下幾個倉庫,在nexus中倉庫組一般只有個maven-public倉庫組
maven-central 中央倉庫的代理倉庫
maven-releases 宿主倉庫的發(fā)布倉庫焕数,用戶發(fā)布公司releases版本代碼
maven-snapshots宿主倉庫的快照倉庫纱昧,用戶發(fā)布公司snapshots版本代碼
3rd party宿主類型的倉庫,存放從本地導(dǎo)入的三方依賴
如果文字無法描述清楚親自安裝nexus后瀏覽倉庫實際下載打包發(fā)布相關(guān)包后即可理解
3百匆、手工配置nexus倉庫
maven-public倉庫組 已默認無需配置
maven-central代理倉庫砌些,默認是http://maven.aliyun.com/nexus/content/groups/public需要修改為阿里云鏡像倉庫
- maven-snapshots宿主倉庫已默認無需配置
- maven-releases宿主倉庫已默認無需配置
-
3rd-party倉庫需要手動創(chuàng)建
再次配置maven-public倉庫組,將3rd-party倉庫加入其中
此處省略圖片
4加匈、改造公司項目配置使用私服
- 在本地maven的settings.xml加入如下配置
<profiles>
<profile>
<id>nexus</id>
<!--依賴包下載配置走私服-->
<repositories>
<repository>
<id>nexus</id>
<name>Nexus </name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件下載配置走私服-->
<pluginRepository>
<id>nexus</id>
<name>Nexus Plugin Repository</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活的profile-->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
這樣會強制將activeProfile里激活的profile對應(yīng)的私服地址應(yīng)用到每個項目中去
- 一般使用時會通過鏡像機制進一步配置存璃,強制讓所有的下載都走私服,最終配置如下
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirros>
<profiles>
<profile>
<id>nexus</id>
<!--依賴包下載配置走私服-->
<repositories>
<repository>
<id>nexus</id>
<name>Nexus </name>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件下載配置走私服-->
<pluginRepository>
<id>nexus</id>
<name>Nexus Plugin Repository</name>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活的profile-->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
5雕拼、nexus權(quán)限管理機制
- 權(quán)限模型 典型的用戶-角色-菜單模式纵东,也叫RBAC模型
-
默認設(shè)置設(shè)置兩個用戶(早期版本有三個用戶)
- admin 擁有所有權(quán)限,默認密碼admin123
- anonymous匿名用戶啥寇,可以下載和查看依賴偎球,無密碼
- 可以自行創(chuàng)建deployment,擁有匿名用戶的所有權(quán)限和倉庫管理辑甜、打包衰絮、發(fā)布等權(quán)限即可
6、部署項目到私服
- 在項目pom.xml增加如下配置
<distributionManagement>
<!--releases版本發(fā)布倉庫-->
<repository>
<id> nexus-releases</id>
<name> Nexus Release Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<!--快照版本發(fā)布倉庫-->
<snapshotRepository>
<id> nexus-snapshots</id>
<name> Nexus Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
- 在maven的settings.xml增加如下配置
<servers>
<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
說明:這里的id對應(yīng)pom配置中的id磷醋,這里的用戶名密碼對應(yīng)上邊再nexus中設(shè)置的deployment用戶的用戶名和密碼
- 常見打包部署命令簡單介紹
- mvn clean package:清理猫牡、編譯、測試邓线、打包
- mvn clean install:清理淌友、編譯煌恢、測試、打包震庭、安裝到本地倉庫
- mvn clean deploy:清理瑰抵、編譯、測試器联、打包二汛、安裝到本地倉庫、部署到遠程私服倉庫
- 手動上次jar包到私服
mvn deploy:deploy-file -DgroupId=com.csource -DartifactId=fastdfs-client-java -Dversion=1.24 -Dpackaging=jar -Dfile=F:\DevelopmentKit\fastdfs_client_v1.24.jar -Durl=http://localhost:8081/repository/3rd-party/ -DrepositoryId=nexus-3rd-party
即是手動上傳如下jar包到私服
<server>
<id>nexus-3rd-party</id>
<username>deployment</username>
<password>deployment123</password>
</server>
類似也可以用mvn instaill:install-file將jar包安裝到本地倉庫