Maven使用阿里云镜像在国内加速下载

下载maven

从官方下载maven安装包,链接地址:https://maven.apache.org/download.cgi

选择对应的版本,下载后解压到本地,例如:D:\software\apache-maven-3.6.3。

配置环境变量

新建环境变量MAVEN_HOME,设置值为您maven的解压目录,例如:D:\software\apache-maven-3.6.3。

编辑环境变量PATH,追加值:%MAVEN_HOME%/bin。

环境变量保存后,打开cmd,执行命令”mvn -v”,查看maven版本。

使用阿里云镜像

进入maven安装目录的conf文件夹,例如D:\software\apache-maven-3.6.3\conf,编辑settings.xml,配置如下:

<?xml version="1.0" encoding="UTF-8"?>

<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">

   <localRepository>D:\repo\maven</localRepository>

  <mirrors>

    <mirror>
        <id>aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>

    <mirror>
        <id>central</id>
        <mirrorOf>central</mirrorOf>
        <name>Central Repository</name>
        <url>https://repo1.maven.org/maven2/</url>
    </mirror>

  </mirrors>

  <profiles>
    <profile>
        <id>aliyun</id>

        <repositories>
            <repository>
                <id>aliyun</id>
                <url>https://maven.aliyun.com/repository/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
                <id>aliyun</id>
                <url>https://maven.aliyun.com/repository/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <!-- tomcat8-maven-plugin 所在仓库 -->
                <id>Alfresco</id>
                <name>Alfresco Repository</name>
                <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>

    <profile>
        <id>central</id>
        <repositories>

            <repository>
                <id>central</id>
                <url>https://repo1.maven.org/maven2</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>https://repo1.maven.org/maven2</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <!-- tomcat8-maven-plugin 所在仓库 -->
                <id>Alfresco</id>
                <name>Alfresco Repository</name>
                <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
      <activeProfile>aliyun</activeProfile>
      <!-- <activeProfile>central</activeProfile> -->
  </activeProfiles>
</settings>

未经允许不得转载:君子如兰 » Maven使用阿里云镜像在国内加速下载

赞 (0)