问题

{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

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐