今天从远端download下公司一个maven项目时,pom.xml文件中一直报错,missing某些包,此时maven中settings.xml的主要配置如下
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
项目中pom.xml配置了客户的私服,如下:
<distributionManagement>
<repository>
<id>bank_central</id>
<name>core Release Repository</name>
<url>http://......:9090/repository/bank_central/</url>
</repository>
<snapshotRepository>
<id>bank_privrepository_snapshots</id>
<name>core Snapshots Repository</name>
<url>http://......:9090/repository/bank_privrepository_snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>bank_privrepository_interfaces</id>
<name>bank_privrepository_interfaces</name>
<url>http://......:9090/repository/bank_privrepository_interfaces/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>bank_privrepository_snapshots</id>
<name>bank_privrepository_snapshots</name>
<url>http://......:9090/repository/bank_privrepository_snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<!--中央仓库,插件安装 -->
<id>nexus</id>
<name>local nexus server</name>
<url>http://......:9090/repository/bank_central/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
经历了反复的clean-build、maven force update及各种可能想得到的操作,某些依赖包依然无法下载。
后来突发奇想,将settings.xml中
<mirrors/>
配置项删除,重新force update,某些包可以下载下来了,但依然缺包,后来查阅各种资料,将setting.xml中*改为central
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
perfect!!!!!!!!!!!!!!!知其然不知其所以然,待更新
官方说明:https://maven.apache.org/guides/mini/guide-mirror-settings.html
*的意思就是(根据mirrorOf和repository的id)匹配所有的库(repository),这样就是说如果你需要某个jar,他会从镜像地址去下载这个jar。不管你配置了多少个库,即使这些库的地址不一样,仍然会从镜像地址访问