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

Maven仓库报501错误,如何强制改用HTTPS获取junit-bom依赖

问题分析与解决方案

为什么HTTP链接没自动重定向到HTTPS?

Maven中央仓库的运营方Sonatype已经彻底禁用了HTTP协议访问,不再对HTTP请求返回重定向响应,而是直接返回501错误强制要求使用HTTPS。另外,你使用的Ant artifact任务本身不会自动将HTTP请求转为HTTPS,必须显式配置HTTPS地址。

强制使用HTTPS的解决步骤

1. 修改build.xml中的仓库配置

找到build.xml里定义artifact:dependencies任务的部分,把中央仓库的地址从http://repo1.maven.org/maven2替换为https://repo1.maven.org/maven2。示例配置:

<artifact:dependencies>
  <remoteRepository id="central" url="https://repo1.maven.org/maven2"/>
  <!-- 保留其他仓库配置 -->
</artifact:dependencies>

确保所有指向中央仓库的配置都使用HTTPS协议,删除或注释掉HTTP版本的仓库定义。

2. 检查系统Maven配置(如果Ant依赖此配置)

如果你的Ant构建依赖系统级的Maven settings.xml,打开~/.m2/settings.xml(Windows路径:C:\Users\<你的用户名>\.m2\settings.xml),找到<repositories>或<mirrors>里的中央仓库配置,将URL改为HTTPS:

<repository>
  <id>central</id>
  <url>https://repo1.maven.org/maven2</url>
</repository>

3. 重新执行构建

修改配置后直接运行构建命令,确保工具从HTTPS地址拉取依赖。

完整错误日志

[artifact:dependencies] Downloading: org/junit/junit-bom/5.9.1/junit-bom-5.9.1.pom from repository central at http://repo1.maven.org/maven2
[artifact:dependencies] Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/junit/junit-bom/5.9.1/junit-bom-5.9.1.pom
[artifact:dependencies] [WARNING] Unable to get resource 'org.junit:junit-bom:pom:5.9.1' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/junit/junit-bom/5.9.1/junit-bom-5.9.1.pom
[artifact:dependencies] An error has occurred while processing the Maven artifact tasks.
[artifact:dependencies]  Diagnosis:
[artifact:dependencies] 
[artifact:dependencies] Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'org.apache.commons:commons-text:jar': POM 'org.junit:junit-bom' not found in repository: Unable to download the artifact from any repository
[artifact:dependencies] 
[artifact:dependencies]   org.junit:junit-bom:pom:5.9.1
[artifact:dependencies] 
[artifact:dependencies] from the specified remote repositories:
[artifact:dependencies]   central (http://repo1.maven.org/maven2),
[artifact:dependencies]   apache.snapshots (https://repository.apache.org/snapshots)
[artifact:dependencies] 
[artifact:dependencies]  for project org.junit:junit-bom
[artifact:dependencies]   org.apache.commons:commons-text:jar:1.10.0
[artifact:dependencies] 
[artifact:dependencies] from the specified remote repositories:
[artifact:dependencies]   RemoteRepo (https://repo1.maven.org/maven2),
[artifact:dependencies]   central-https (https://repo1.maven.org/maven2)
[artifact:dependencies] 
[artifact:dependencies] Path to dependency: 
[artifact:dependencies]     1) org.apache.maven:super-pom:pom:2.0
[artifact:dependencies] 
[artifact:dependencies] 
[artifact:dependencies] 

BUILD FAILED
D:\x\y\build.xml:63: Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'org.apache.commons:commons-text:jar': POM 'org.junit:junit-bom' not found in repository: Unable to download the artifact from any repository

  org.junit:junit-bom:pom:5.9.1

from the specified remote repositories:
  central (http://repo1.maven.org/maven2),
  apache.snapshots (https://repository.apache.org/snapshots)

 for project org.junit:junit-bom
  org.apache.commons:commons-text:jar:1.10.0

from the specified remote repositories:
  RemoteRepo (https://repo1.maven.org/maven2),
  central-https (https://repo1.maven.org/maven2)

Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0



Total time: 1 second

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 03:05:19