Java学习笔记之五:Nexus配置为强制从maven私服下载
一、配置setting.xml
路徑為C:\Users\當前用戶名\.m2\settings.xml
1,在<profiles></profiles>中增加下面這段
第一段是依賴倉庫
第二段是插件倉庫
id為central 這里用了central后,E:\Develop\Maven\apache-maven-3.8.3\lib\maven-model-builder-3.8.3.jar 中的org\apache\maven\model\pom-4.0.0.xml 中id為central的依賴倉庫和插件倉庫就失效了
<profile><id>nexus</id><repositories><repository><id>central</id><name>Nexus </name><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>central</id><name>Nexus Plugin Repository</name><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile>其中?<releases><enabled>true</enabled></releases>表示release版本從這里下載依賴/插件
? ? ? ?<snapshots><enabled>true</enabled></snapshots>表示snapshots版本從這里下載依賴/插件
2,配置激活,與<profiles></profiles>同級別
<activeProfiles><activeProfile>nexus</activeProfile></activeProfiles>3,配置鏡像
<mirrors></mirrors>中也把所有鏡像都指向nexus的maven私服中去
<mirror><id>nexus</id><mirrorOf>*</mirrorOf><url>http://localhost:8081/repository/maven-public/</url> </mirror>其中的url來自這里
4、以上配置的含義:
依賴和插件本地倉庫沒有,去profile中配置的central中央倉庫里面尋找
如果支持,就不找profile的url,就去找mirrors鏡像配置的url
也就是http://localhost:8081/repository/maven-public/
這個私服的倉庫組地址上面去
二、實驗
1、在項目中加入kafka依賴,應該走私服阿里云下載,私服上有一份依賴,本地也有一份依賴
在項目的pom.xml中,增加kafka的依賴
<dependency><groupId>org.apache.kafka</groupId><artifactId>kafka_2.10</artifactId><version>0.10.2.1</version> </dependency>?eclipse馬上開始使用端口號8081 也就是Nexus中的maven私服開始幫我下載
2,驗證
到nexus里面看,已經下載過來了
?到.m2本地倉庫看
?都有了
搭建完成已走通!
--------------------------------------------------
每天學一點Java,年底達成初級可期也
--------------------------------------------------
總結
以上是生活随笔為你收集整理的Java学习笔记之五:Nexus配置为强制从maven私服下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 活字印刷(dfs)
- 下一篇: 我的2018:用一年的时间写一份年终总结