Maven私服搭建(Nexus Repository Manager 3)
下載和安裝
下載地址:https://help.sonatype.com/repomanager3/download
注意:Nexus Repository Manager 3是一個(gè)Java服務(wù)器應(yīng)用程序,安裝需要?jdk1.8以上的版本。
下載解壓后,用命令行到解壓目錄的bin目錄下運(yùn)行?nexus.exe /run(Linux運(yùn)行./nexus run),啟動(dòng)完成后會(huì)顯示“Started Sonatype Nexus”:
-------------------------------------------------Started Sonatype Nexus OSS 3.16.2-01-------------------------------------------------訪問(wèn)Nexus管理后臺(tái)
Nexus管理后臺(tái)地址:http://localhost:8081/
點(diǎn)擊右上角Sign in登錄,默認(rèn)賬號(hào)和密碼為:admin/admin123
在Repositories 倉(cāng)庫(kù)管理界面中有多種默認(rèn)的倉(cāng)庫(kù),也可以添加新的倉(cāng)庫(kù),本實(shí)例直接使用默認(rèn)的倉(cāng)庫(kù):
maven-central,Type為proxy,表示代理倉(cāng)庫(kù)。代理倉(cāng)庫(kù)用來(lái)代理遠(yuǎn)程倉(cāng)庫(kù)(maven-central代理的是超級(jí)POM中配置的Maven中央倉(cāng)庫(kù)),當(dāng)在下載組件時(shí),如果代理倉(cāng)庫(kù)搜索不到,則會(huì)把請(qǐng)求轉(zhuǎn)發(fā)到遠(yuǎn)程倉(cāng)庫(kù)從遠(yuǎn)程倉(cāng)庫(kù)下載。從遠(yuǎn)程倉(cāng)庫(kù)下載后會(huì)緩存到代理倉(cāng)庫(kù),下次還有該組件的請(qǐng)求則會(huì)直接到代理倉(cāng)庫(kù)下載,不會(huì)再次請(qǐng)求遠(yuǎn)程倉(cāng)庫(kù)。
maven-releases/maven-snapshots,Type為hosted,表示為宿主倉(cāng)庫(kù)。宿主倉(cāng)庫(kù)主要用來(lái)部署團(tuán)隊(duì)內(nèi)部使用的內(nèi)部組件,默認(rèn)的maven-releases和maven-snapshots分別用來(lái)部署團(tuán)隊(duì)內(nèi)部的發(fā)布版本組件和快照版本組件。
配置代理倉(cāng)庫(kù)
配置settings.xml:
<settings><!-- 配置鏡像,此處攔截所有遠(yuǎn)程倉(cāng)庫(kù)的請(qǐng)求到代理倉(cāng)庫(kù)--><mirrors><mirror><id>nexus</id><mirrorOf>*</mirrorOf><url>http://localhost:8081/repository/maven-central/</url></mirror></mirrors><!-- 配置遠(yuǎn)程庫(kù)和遠(yuǎn)程插件庫(kù)--><profiles><profile><id>nexus</id><!-- Maven用于填充構(gòu)建系統(tǒng)本地存儲(chǔ)庫(kù)的遠(yuǎn)程倉(cāng)庫(kù)集合--><repositories><repository><id>central</id><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><!-- 類似于repositories元素,指定Maven可以在哪里找到Maven插件的遠(yuǎn)程倉(cāng)庫(kù)位置--><pluginRepositories><pluginRepository><id>central</id><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile></profiles><!-- 激活profiles配置 --><activeProfiles><activeProfile>nexus</activeProfile></activeProfiles> </settings>創(chuàng)建Maven項(xiàng)目,pom.xml如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.nocoffee</groupId><artifactId>coffee-api</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>coffee-api</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies> </project>執(zhí)行mvn clean,執(zhí)行mvn clean需要下載maven-clean-plugin插件,通過(guò)Browse界面可以看到因?yàn)閳?zhí)行mvn clean而下載的maven-clean-plugin.jar:
注意:如果界面為空,表示沒(méi)有下載,原因是之前下載過(guò)該插件到本地倉(cāng)庫(kù),需要把本地倉(cāng)庫(kù)的maven-clean-plugin插件刪除,我的本地倉(cāng)庫(kù)路徑為D:\Reporsitory,所以需要?jiǎng)h掉文件夾:D:\Reporsitory\org\apache\maven\plugins\maven-clean-plugin,然后重新構(gòu)建即可。
配置宿主倉(cāng)庫(kù)
settings.xml增加如下配置:
<servers><server><id>nexus</id><username>admin</username><password>admin123</password></server> </servers>配置pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.nocoffee</groupId><artifactId>coffee-api</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>coffee-api</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><distributionManagement><repository><id>nexus</id><name>maven-releases</name><url>http://localhost:8081/repository/maven-releases/</url></repository><snapshotRepository><id>nexus</id><name>maven-snapshots</name><url>http://localhost:8081/repository/maven-snapshots/</url></snapshotRepository></distributionManagement> </project>執(zhí)行mvn clean deploy將項(xiàng)目打包并發(fā)布到宿主倉(cāng)庫(kù),構(gòu)建成功后到Browse中maven-snapshots庫(kù)查看(因?yàn)轫?xiàng)目版本為0.0.1-SNAPSHOT,是帶SNAPSHOT的快照版本):
maven-releases庫(kù)
需要將項(xiàng)目版本改成發(fā)布版本,在pom.xml中0.0.1-SNAPSHOT去掉-SNAPSHOT,改為0.0.1。重新執(zhí)行mvn clean deploy:
注意:maven-releases庫(kù)默認(rèn)不能重新發(fā)布,需要可重新發(fā)布則需要修改該倉(cāng)庫(kù)配置。
測(cè)試重新發(fā)布到maven-releases庫(kù),執(zhí)行mvn clean deploy將會(huì)構(gòu)建失敗:
將maven-releases庫(kù)中Deployment pollcy改為Allow redeploy既可:
?
?
原文鏈接?https://www.cnblogs.com/seve/p/10982603.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/mzdljgz/p/11601588.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Maven私服搭建(Nexus Repository Manager 3)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: SpringBoot学习笔记:Sprin
- 下一篇: Linux yum 报错:One of