采用阿里云Maven镜像仓库来加速依赖下载

背景

众所周知,墙外的Maven仓库访问起来真的是炒鸡慢,幸好阿里云做了一个Maven镜像仓库,可以极大地提升我们下载依赖的速度。

步骤

  1. 找到Maven的settings文件,比如我是mac电脑,用brew安装的maven,那么该文件地址是/usr/local/Cellar/maven/3.3.3/libexec/conf/settings.xml

  2. 打开编辑,找到配置mirrors的地方,然后添加阿里云的镜像地址:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    <mirrors>
    <!-- mirror
    | Specifies a repository mirror site to use instead of a given repository. The repository that
    | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
    | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
    |
    <mirror>
    <id>mirrorId</id>
    <mirrorOf>repositoryId</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://my.repository.com/repo/path</url>
    </mirror>
    -->
    <!-- 阿里云Maven仓库 -->
    <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
    </mirror>
    </mirrors>
  3. 保存退出后即可尽情享受。当然笔者在实际的使用过程中还是发现有点不稳定,所以建议大家还是自建maven仓库或者对maven设置代理。

坚持原创技术分享,您的支持将鼓励我继续创作!