0
点赞
收藏
分享

微信扫一扫

maven配置阿里云镜像仓库不生效的问题

_刘彦辉 2022-01-28 阅读 134
mavenjava

问题

{MAVEN_HOME}/conf/settings.xml中添加镜像配置:

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

但是项目更新时仍然会从http://repo.maven.apache.org/maven2下载依赖。

解决方法

在项目的pom.xml中添加如下配置

  <repositories>
    <repository>
      <id>central</id>
      <url>https://maven.aliyun.com/repository/public</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>https://maven.aliyun.com/repository/public</url>
    </pluginRepository>
  </pluginRepositories>

原因

项目的pom会继承自super pom,在super pom中指定了从仓库的地址:

<repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
 
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>

因此需要在项目中覆盖这一配置。

参考

配置了maven的国内镜像后,问题:(https://repo.maven.apache.org/maven2): Not authorized , ReasonPhrase:Authorizatio

举报

相关推荐

0 条评论