仓库优先级
- 首先
假如pom.xml 文件中设置了repository 优先级最高(前提没有被mirrof接管) - 其次setting.xml(mirrorOf 标签中值相同 ,靠前的优先级高)
<mirrorOf>central</mirrorOf> 大于 <mirrorOf></mirrorOf>
3 如果setting.xml设置了<mirrorOf></mirrorOf> ,那么在setting.xml和pom.xml中设置的<repository> 都将失效
localRepository 配置本地仓库
E:\maven_repository
mirror 可以拦截对远程仓库的请求 , 改变对目标仓库的下载地址
测试
配置maven环境

-
使用maven默认配置,从中央仓库下载依赖jar包 速度缓慢
image.png
-
切换阿里云仓库
image.png
-
切换nexus 私服
image.png
-
当有多个mirror 配置时
<mirrorOf>central</mirrorOf>
优先级高于<mirrorOf>*</mirrorOf>
image.png
-
注意 当<mirrorOf>central</mirrorOf>对应的仓库没有jar包时 配置<mirrorOf>*</mirrorOf>并不会兜底作为第二仓库继续寻找
image.png 所以每个setting.xml 保留一个central 配置即可,默认第一个生效(多个相同
<mirrorOf>central</mirrorOf>
时) -
业务环境我们通常使用私服 且配置(<mirrorOf>*</mirrorOf>)

- 当pom.xml 中也设置了repository 仓库时
- pom.xml 设置的repository仓库名为spring的优先级高于setting中配置的central中央仓库
<repositories>
<repository>
<id>spring</id>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

- 当setting.xml文件中配置 时,会强制接手仓库代理
-- <mirrof> 相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote repository地址,重定向到mirror里配置的地址

故障记录
[ERROR] Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor f
or org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: org.apache.maven:maven-parent:pom:23 was not found in http://10.39.15.6:8081/repository/maven
-public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of mynex
us has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
PS D:\JAVASTUDY\mvn-test>
解决办法
mvn -U package
网友评论