Maven實戰_在setting.xml文件中同時配置local nexus和aliyun nexus
為了提升maven下載jar包的速度,會使用阿里云私服進行加速,在setting.xml文件的mirrors節點下,添加如下配置:
<mirror> <id>aliyun-nexus</id> <mirrorOf>central</mirrorOf> <name>aliyun nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
mirror可以攔截對遠程倉庫的請求,改變對目標倉庫的下載地址,一般情況下,maven下載jar包會默認到中央倉庫central進行下載,
mirrorOf可以理解為“為某個倉庫(repository)的鏡像”,填寫的是repositoryId,當填寫為 * 時,代表匹配所有的倉庫,代理所有的倉庫。
mirror相當于一個攔截器,它會攔截maven對remote repository的相關請求,重定向到mirror.url指定的地址。
公司里面的項目使用了自定義jar包,那么,就要搭建自己的nexus,將鏡像配置改成如下:
<mirror> <id>local-nexus</id> <mirrorOf>central</mirrorOf> <name>local nexus</name> <url>http://ip:port/repository/maven-public/</url> </mirror>
因為公司內部的私服是外網部署,并且帶寬很低,導致項目在使用阿里云流水線部署java構建時,下載jar包速度非常慢。
這個時候就想著使用阿里云私服和自己公司的私服,下載spring相關的jar包到aliyun nexus進行下載,當需要用到自定義的jar時就使用local nexus
我們需要用到setting.xml中的另一個配置profies,來配置自定義倉庫
<profiles> <profile> <!-- 私服id --> <id>Nexus</id> <repositories> <repository> <id>aliyun-nexus</id> <url>https://maven.aliyun.com/repository/public</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>true</enabled></releases> </repository> </repositories> <!--指定插件下載地址--> <pluginRepositories> <pluginRepository> <id>aliyun-plugin-nexus</id> <url>https://maven.aliyun.com/repository/public</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>true</enabled></releases> </pluginRepository> </pluginRepositories> </profile> </profiles> <!--啟動私服倉庫 --> <activeProfiles> <activeProfile>Nexus</activeProfile> </activeProfiles>
參考文章:
http://www.rzrgm.cn/Vincent-yuan/p/14974938.html
http://www.rzrgm.cn/chuimber/p/18299166
https://blog.csdn.net/weixin_43811057/article/details/132720550
業務需求變更永無休止,技術前進就永無止境!

浙公網安備 33010602011771號