美文网首页
maven 仓库加速及加载优先级

maven 仓库加速及加载优先级

作者: 开始懂了90 | 来源:发表于2023-03-17 15:14 被阅读0次

仓库优先级

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

相关文章

  • 阿里云maven仓库地址——加速maven构建

    国内访问国外的maven仓库比较慢,阿里云提供一个公共的maven仓库,访问速度快,加速maven构建。在mave...

  • 三、maven 私服搭建

    一、maven 仓库及私服介绍 什么是maven 仓库?maven 是基于项目对象模型(POM),可以通过一小段描...

  • maven配置

    1.maven仓库的加载顺序 本地仓库 > setting.xml中的配置的仓库(在profile标签中设置的re...

  • 12.2 Anroid Studio项目如何使用镜像加速依赖安装

    一般国内访问jcenter,maven仓库比较慢,所以可以采用如下方法使用镜像加速。 选择镜像 maven镜像,国...

  • maven仓库理解

    前言 使用maven也有一段时间,经常发现有些jar包拉取不到,所以整理出比较详细的maven仓库优先级,更加深层...

  • Maven 仓库管理

    本节主要介绍如何配置 Maven 仓库,发布 jar 包到 Maven 仓库 Maven 仓库是什么? Maven...

  • 使用docker-maven-plugin插件实现Docker构

    使用Maven插件实现项目打包及Docker构建并提交到私有仓库 以下内容非教程,不适合对Docker及Maven...

  • idea中用maven搭建ssm框架

    首先下载maven,并将maven解压到自己想要保存的路径下: 配置mave的本地仓库,存储通过坐标加载过来的ja...

  • 【maven】仓库的优先级顺序

    在maven中,仓库可以分为:本地仓库、远程仓库。远程仓库可以分为:中央仓库、私服仓库。中央仓库是maven官方指...

  • Maven实战之Maven仓库

    Maven实战之Maven仓库 Maven仓库作用 仓库,顾名思义就是存放物品的地方。在Maven中,我们可以将其...

网友评论

      本文标题:maven 仓库加速及加载优先级

      本文链接:https://www.haomeiwen.com/subject/oghjrdtx.html