maven 仓库加速及加载优先级

2023-03-17  本文已影响0人  开始懂了90

仓库优先级

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

配置maven环境


image.png
  1. 使用maven默认配置,从中央仓库下载依赖jar包 速度缓慢


    image.png
  2. 切换阿里云仓库


    image.png
  3. 切换nexus 私服


    image.png
  4. 当有多个mirror 配置时 <mirrorOf>central</mirrorOf> 优先级高于<mirrorOf>*</mirrorOf>

    image.png
  5. 注意 当<mirrorOf>central</mirrorOf>对应的仓库没有jar包时 配置<mirrorOf>*</mirrorOf>并不会兜底作为第二仓库继续寻找

    image.png 所以每个setting.xml 保留一个central 配置即可,默认第一个生效(多个相同<mirrorOf>central</mirrorOf>时)
  6. 业务环境我们通常使用私服 且配置(<mirrorOf>*</mirrorOf>)

image.png
  1. 当pom.xml 中也设置了repository 仓库时
    <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>
image.png image.png

故障记录

[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
上一篇 下一篇

猜你喜欢

热点阅读