maven配置阿里云镜像仓库

全局配置:添加镜像到 maven 的 setting.xml 文件中,这样就不需要每次在项目的 pom 文件中配置了

  在settings.xml文件中的mirrors下添加mirror标签,可以配置多个,按配置先后顺序使用,如果第一个不可用会自动使用第二个。

<!-- 阿里云仓库1 -->
    <mirror>      
      <id>nexus-aliyun</id>    
      <name>nexus-aliyun</name>  
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>    
      <mirrorOf>central</mirrorOf>      
    </mirror>

    <!-- 阿里云仓库2 -->
    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>

  < mirrorOf> 可以设置为哪个中央仓库做镜像,为名为 “central” 的中央仓库做镜像,写作< mirrorOf>central< /mirrorOf>;

  为所有中央仓库做镜像,写作< mirrorOf>*< /mirrorOf>。maven默认中央仓库的id 为 central。id是唯一的。

单项目配置:

  单项目配置时,需要修改项目的 pom 文件。pom文件中,没有mirror元素。在 pom 文件中,通过覆盖默认的中央仓库的配置,实现中央仓库地址的变更。 

<repositories>
        <repository>
            <id>central</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <layout>default</layout>
            <!-- 是否开启发布版构件下载 -->
            <releases>
                <enabled>true</enabled>
            </releases>
            <!-- 是否开启快照版构件下载 -->
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

  默认中央仓库的id 为 central。id是唯一的,因此使用< id>central< /id>覆盖了默认的中央仓库。

原文地址:https://www.cnblogs.com/roadlandscape/p/12348692.html