You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven配置后仍报501错误,仓库URL重复拼接问题求助

Maven仓库URL重复拼接导致501错误问题

我对Maven不太熟悉,正在本地搭建共享项目。得知Maven仓库存在安全问题,已在pom.xml的<repositories>节点中添加如下HTTPS协议的中央仓库配置:

<repository>
  <id>central</id>
  <name>Central Repository</name>
  <url>https://repo.maven.apache.org/maven2</url> 
  <layout>default</layout>
  <snapshots>
    <enabled>false</enabled> 
  </snapshots>
</repository>

但仍出现501错误,且发现仓库URL被重复拼接,报错信息如下:

Failed to look for file: http://repo.maven.apache.org/maven2/http://repo.maven.apache.org/maven2/org/codehaus/mojo/gwt-maven-plugin/2.4.0/gwt-maven-plugin-2.4.0.pom.

后续报错信息:

Failure to transfer org.codehaus.mojo:gwt-maven-plugin:pom:2.4.0 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.codehaus.mojo:gwt-maven-plugin:pom:2.4.0 from/to central (http://repo.maven.apache.org/maven2): Failed to look for file: http://repo.maven.apache.org/maven2/http://repo.maven.apache.org/maven2/org/codehaus/mojo/gwt-maven-plugin/2.4.0/gwt-maven-plugin-2.4.0.pom.

请问为何URL会被重复拼接而非替换?该如何解决?


问题原因

  • 本地仓库缓存了旧的HTTP仓库配置:Maven会把之前失败的请求记录缓存到本地仓库的_remote.repositories文件中,即便你在pom.xml里改成了HTTPS,缓存里的旧HTTP地址依然生效,导致URL拼接异常。
  • 全局settings.xml存在冲突配置:如果你的全局Maven配置文件(路径一般是~/.m2/settings.xml或Maven安装目录下的conf/settings.xml)里,还配置了ID为central的HTTP仓库,会和pom.xml中的HTTPS配置冲突,引发拼接问题。
  • 历史错误URL缓存:之前如果有错误的仓库URL配置(比如末尾多了斜杠、格式错误),缓存后也会导致后续请求的URL拼接出错。

解决方法

  • 清理本地缓存文件:找到本地仓库中对应依赖的目录(例如org/codehaus/mojo/gwt-maven-plugin/2.4.0),删除该目录下的_remote.repositories和所有.lastUpdated文件,让Maven重新发起仓库请求。
  • 检查全局settings.xml:打开全局配置文件,确认<repositories>节点里没有ID为central的HTTP仓库。如果有,将其URL改为HTTPS格式,或者直接删除该配置(Maven默认中央仓库已改为HTTPS)。
  • 强制更新依赖:执行Maven命令时添加-U参数,强制忽略缓存重新拉取依赖:
    mvn clean install -U
    
  • 确认URL格式正确性:确保pom.xml中仓库URL末尾没有多余斜杠,正确格式为https://repo.maven.apache.org/maven2。

内容的提问来源于stack exchange,提问作者Erik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 22:11:02