应用场景
在使用单镜像节点配置时,例如使用阿里云的官方单节点镜像
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
此时,如果出现某些依赖包不存在阿里云的 central 仓和 jcenter 仓中(public 是 central 仓和 jcenter 仓的聚合仓),则会发生依赖处理错误,无法顺利打包
而阿里云其实代理了多个仓库,当某些依赖包不存在于 public 仓时,可以去其他的仓库寻找,找到后成功导入依赖,则可以顺利打包
例如 org.pentaho:pentaho-aggdesigner-algorithm:jar:5.1.5-jhyde
,因为该依赖包位于 spring-plugin 仓库中,根本不存在中央仓库中,因此使用 public 仓库是无法下载的,需要配置阿里云的 spring-plugin 仓库镜像
多镜像节点配置
根据阿里云官方代理仓库表
对应配置 central、jcenter、google、spring 和 spring-plugin
注意,在多镜像节点配置的过程中,不能使用 <mirrorOf>*</mirrorOf>
配置,否则会导致其他节点配置无效
<!-- central -->
<mirror>
<id>aliyunmaven-central</id>
<mirrorOf>central</mirrorOf>
<name>central</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<!-- jcenter -->
<mirror>
<id>aliyunmaven-jcenter</id>
<mirrorOf>jcenter</mirrorOf>
<name>jcenter</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<!-- google -->
<mirror>
<id>aliyunmaven-google</id>
<mirrorOf>google</mirrorOf>
<name>google</name>
<url>https://maven.aliyun.com/repository/google</url>
</mirror>
<!-- spring -->
<mirror>
<id>aliyunmaven-spring</id>
<mirrorOf>spring</mirrorOf>
<name>spring</name>
<url>https://maven.aliyun.com/repository/spring</url>
</mirror>
<!-- spring-plugin -->
<mirror>
<id>aliyunmaven-spring-plugin</id>
<mirrorOf>spring-plugin</mirrorOf>
<name>spring-plugin</name>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
</mirror>
配置完镜像,保存重启 IDE,再次导入 maven 即可完成