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

Eclipse执行Maven install报错:Access denied,错误码403 Forbidden

解决Maven Install时403 Forbidden(中央仓库访问拒绝)及Surefire插件执行失败问题

嘿,我看你碰到的核心问题是访问旧HTTP协议的Maven中央仓库被403拒绝,进而导致maven-surefire-plugin的依赖拉取失败,最终测试阶段执行炸锅了。别慌,下面是一步步的解决方案:

1. 把中央仓库地址换成HTTPS

Maven官方早就停用了HTTP协议的中央仓库,现在强制用HTTPS。你得把配置里的旧地址换掉:

  • 要是改全局配置(~/.m2/settings.xml或者Maven安装目录下的conf/settings.xml):
    找到<repositories>和<pluginRepositories>节点,把所有http://repo.maven.apache.org/maven2改成https://repo.maven.apache.org/maven2
  • 要是改项目的pom.xml:
    添加或者更新仓库配置块:
    <repositories>
      <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>false</enabled>
        </snapshots>
      </repository>
    </repositories>
    <pluginRepositories>
      <pluginRepository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>false</enabled>
        </snapshots>
      </pluginRepository>
    </pluginRepositories>
    

2. 清理本地仓库的失效缓存

有时候本地Maven仓库里已经缓存了拉取失败的坏文件,会一直报错。试试这条命令强制清理并重新拉取:

mvn clean install -U

-U参数会让Maven忽略本地缓存的失效依赖,强制从仓库更新。

3. 排查网络和代理问题

如果你在公司内网,大概率是代理或者防火墙搞的鬼:

  • 检查settings.xml里的代理配置(如果有的话),确保代理支持HTTPS,地址和端口都正确
  • 可以试试切换到个人网络(比如手机热点),排除公司防火墙的限制

4. 升级Surefire插件版本(可选)

你用的surefire插件是2.12.4,版本有点老了,可能和当前Maven版本或者项目存在兼容性问题。可以升级到一个稳定的新版本,比如3.0.0-M7:
在项目pom.xml的<build><plugins>里更新插件配置:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M7</version>
</plugin>

做完这些步骤后,重新跑mvn install,应该就能解决403和插件执行失败的问题了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:00:32