日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Maven私服搭建(Nexus Repository Manager 3)

發布時間:2025/3/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Maven私服搭建(Nexus Repository Manager 3) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下載和安裝

下載地址:https://help.sonatype.com/repomanager3/download

注意:Nexus Repository Manager 3是一個Java服務器應用程序,安裝需要?jdk1.8以上的版本。

下載解壓后,用命令行到解壓目錄的bin目錄下運行?nexus.exe /run(Linux運行./nexus run),啟動完成后會顯示“Started Sonatype Nexus”:

-------------------------------------------------Started Sonatype Nexus OSS 3.16.2-01-------------------------------------------------

訪問Nexus管理后臺

Nexus管理后臺地址:http://localhost:8081/
點擊右上角Sign in登錄,默認賬號和密碼為:admin/admin123

在Repositories 倉庫管理界面中有多種默認的倉庫,也可以添加新的倉庫,本實例直接使用默認的倉庫:
maven-central,Type為proxy,表示代理倉庫。代理倉庫用來代理遠程倉庫(maven-central代理的是超級POM中配置的Maven中央倉庫),當在下載組件時,如果代理倉庫搜索不到,則會把請求轉發到遠程倉庫從遠程倉庫下載。從遠程倉庫下載后會緩存到代理倉庫,下次還有該組件的請求則會直接到代理倉庫下載,不會再次請求遠程倉庫。

maven-releases/maven-snapshots,Type為hosted,表示為宿主倉庫。宿主倉庫主要用來部署團隊內部使用的內部組件,默認的maven-releases和maven-snapshots分別用來部署團隊內部的發布版本組件和快照版本組件。


配置代理倉庫

配置settings.xml:

<settings><!-- 配置鏡像,此處攔截所有遠程倉庫的請求到代理倉庫--><mirrors><mirror><id>nexus</id><mirrorOf>*</mirrorOf><url>http://localhost:8081/repository/maven-central/</url></mirror></mirrors><!-- 配置遠程庫和遠程插件庫--><profiles><profile><id>nexus</id><!-- Maven用于填充構建系統本地存儲庫的遠程倉庫集合--><repositories><repository><id>central</id><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><!-- 類似于repositories元素,指定Maven可以在哪里找到Maven插件的遠程倉庫位置--><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>

創建Maven項目,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>

執行mvn clean,執行mvn clean需要下載maven-clean-plugin插件,通過Browse界面可以看到因為執行mvn clean而下載的maven-clean-plugin.jar:


注意:如果界面為空,表示沒有下載,原因是之前下載過該插件到本地倉庫,需要把本地倉庫的maven-clean-plugin插件刪除,我的本地倉庫路徑為D:\Reporsitory,所以需要刪掉文件夾:D:\Reporsitory\org\apache\maven\plugins\maven-clean-plugin,然后重新構建即可。

配置宿主倉庫

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>

執行mvn clean deploy將項目打包并發布到宿主倉庫,構建成功后到Browse中maven-snapshots庫查看(因為項目版本為0.0.1-SNAPSHOT,是帶SNAPSHOT的快照版本):

maven-releases庫

需要將項目版本改成發布版本,在pom.xml中0.0.1-SNAPSHOT去掉-SNAPSHOT,改為0.0.1。重新執行mvn clean deploy:

注意:maven-releases庫默認不能重新發布,需要可重新發布則需要修改該倉庫配置。
測試重新發布到maven-releases庫,執行mvn clean deploy將會構建失敗:

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.112 s [INFO] Finished at: 2019-06-10T16:34:29+08:00 [INFO] Final Memory: 18M/164M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project coffee-api: Failed to deploy artifacts: Could not transfer artifact com.nocoffee:coffee-api:jar:0.0.1 from/to nexus (http://localhost:8081/repository/maven-releases/): Failed to transfer file: http://localhost:8081/repository/maven-releases/com/nocoffee/coffee-api/0.0.1/coffee-api-0.0.1.jar. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

將maven-releases庫中Deployment pollcy改為Allow redeploy既可:

?

?

原文鏈接?https://www.cnblogs.com/seve/p/10982603.html

?

轉載于:https://www.cnblogs.com/mzdljgz/p/11601588.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Maven私服搭建(Nexus Repository Manager 3)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。