目标
分别配置两个nexus镜像源,目的: 编译时,先从nexus1尝试下载依赖,如果失败,到nexus2下载依赖,再失败,去公网中央仓库下载镜像
配置
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus1</id>
<mirrorOf>nexus1</mirrorOf>
<url>http://nexus1.com/nexus/repository/maven-delivery/</url>
</mirror>
<mirror>
<id>nexus2</id>
<mirrorOf>nexus2</mirrorOf>
<url>http://nexus2.com/repository/maven-public/</url>
</mirror>
</mirrors>
<!-- 配置连接密钥,如果需要认证 -->
<servers>
<server>
<id>nexus1</id>
<username>demo</username>
<password>demo001</password>
</server>
</servers>
<!-- The resolution of multiple Repositories only works with profiles!-->
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus1</id>
<url>http://nexus1.com/nexus/repository/maven-delivery/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>nexus2</id>
<url>http://nexus2.com/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus1</id>
<url>http://nexus1.com/nexus/repository/maven-delivery/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>nexus2</id>
<url>http://nexus2.com/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
测试
使用mvn插件下载一个不存在的依赖,查看效果
mvn dependency:get -DgroupId=com.github.ggdefe -DartifactId=ggdefe -Dversion=1.0.0
输出
标签:nexus1,顺序,http,nexus,maven,nexus2,镜像,com
From: https://www.cnblogs.com/xiaojiluben/p/16620945.html