Skip to content

配置国内 Maven 镜像源

在 pom.xml 文件中配置 Maven 的镜像源,以加快 Maven 项目构建和依赖项下载速度。

修改pom.xml

xml
<project>
  ...
  <repositories>
    <repository>
      <id>aliyun</id>
      <url>https://maven.aliyun.com/repository/public</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>aliyun</id>
      <url>https://maven.aliyun.com/repository/public</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
  ...
</project>

说明

<repositories><pluginRepositories>元素添加到pom.xml文件中,并将阿里云的 Maven 镜像源配置为<repository><pluginRepository>元素的子元素。

在配置镜像源时,需要指定该镜像源的idurlreleasessnapshots属性。

releasessnapshots属性用于指定 Maven 是否应该从镜像源下载发布版或快照版的依赖项。

注意,如果在构建 Maven 项目时遇到了下载依赖项速度慢的问题,可以尝试配置其他的 Maven 镜像源。

常见的国内镜像源包括阿里云、华为云、清华大学、中科大等。