将Maven源改为国内阿里云仓库

大数据学习路线图

【版权声明】版权所有,严禁转载,严禁用于商业用途,侵权必究。
在使用Maven打包Scala程序时,默认是从位于国外的Maven中央仓库下载相关的依赖,造成我们从国内下载依赖时速度很慢。

可以通过修改Maven的配置文件,让Maven到国内的阿里云仓库下载相关依赖,大大提高打包的速度。

cd /usr/local/maven/conf
vim settings.xml

settings.xml中的文本改为以下内容:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云谷歌仓库</name>
        <url>https://maven.aliyun.com/repository/google</url>
    </mirror>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云阿帕奇仓库</name>
        <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云spring仓库</name>
        <url>https://maven.aliyun.com/repository/spring</url>
    </mirror>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云spring插件仓库</name>
        <url>https://maven.aliyun.com/repository/spring-plugin</url>
    </mirror>
</mirrors>
</settings>

接下来参考在ECS实例的Ubuntu系统中安装编译打包工具Maven,测试一下换了国内源后Maven打包的速度。我用的是一台从来没有运行过Maven打包的机器测试,也就是说这是第一次运行。

屏幕上会输出类似信息:

Downloading from aliyunmaven: https://maven.aliyun.com/repository/public/commons-lang/commons-lang/2.1/commons-lang-2.1.jar
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/org/codehaus/plexus/plexus-interpolation/1.15/plexus-interpolation-1.15.jar (60 kB at 228 kB/s)
Downloading from aliyunmaven: https://maven.aliyun.com/repository/public/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/org/codehaus/plexus/plexus-io/2.0.2/plexus-io-2.0.2.jar (58 kB at 196 kB/s)
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/org/codehaus/plexus/plexus-archiver/2.1/plexus-archiver-2.1.jar (184 kB at 603 kB/s)
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/commons-lang/commons-lang/2.1/commons-lang-2.1.jar (208 kB at 478 kB/s)
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar (38 kB at 80 kB/s)
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar (226 kB at 454 kB/s)
[INFO] Building jar: /home/hadoop/code/sparkapp2/target/simple-project-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:50 min
[INFO] Finished at: 2020-07-08T11:26:23+08:00
[INFO] ------------------------------------------------------------------------

可见速度相比原来使用Maven中央仓库时快得多。