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

如何在Maven Wrapper中允许HTTP仓库访问?

解决Maven Wrapper无法识别settings.xml中HTTP仓库配置的问题

问题分析

Maven 3.8+版本默认拦截所有HTTP协议的仓库访问,若Maven Wrapper未正确加载你配置的settings.xml,就会触发maven-default-http-blocker的拦截错误。

具体解决方法

1. 执行命令时显式指定settings文件路径

直接在mvnw命令后添加-s参数指定本地settings.xml路径,确保Wrapper加载正确配置:

./mvnw package -s ~/.m2/settings.xml

2. 添加项目级settings.xml(推荐)

在项目根目录下创建.mvn/settings.xml文件,写入允许HTTP私有仓库的配置。Maven Wrapper会优先加载项目内的配置文件,无需每次命令指定。

示例配置(根据你的私有仓库调整):

<settings>
  <mirrors>
    <!-- 调整默认拦截规则,排除你的私有仓库 -->
    <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*,!priv-xxx-libs-release</mirrorOf>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>allow-private-http-repo</id>
      <activeByDefault>true</activeByDefault>
      <repositories>
        <repository>
          <id>priv-xxx-libs-release</id>
          <url>http://你的私有仓库地址/</url>
          <!-- 显式允许不安全的HTTP协议 -->
          <allowInsecureProtocol>true</allowInsecureProtocol>
        </repository>
      </repositories>
    </profile>
  </profiles>
</settings>

3. 配置Wrapper强制使用指定settings

修改项目根目录下的.mvn/wrapper/maven-wrapper.properties文件,添加以下配置,让Wrapper每次启动都加载你的本地settings.xml:

maven.settings.path=~/.m2/settings.xml

关键注意点

  • 必须给目标私有仓库添加<allowInsecureProtocol>true</allowInsecureProtocol>,这是Maven 3.8+允许HTTP仓库的必要配置。
  • 调整maven-default-http-blocker的mirrorOf规则,排除你的私有仓库,避免被拦截。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 12:20:40