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

Maven多模块项目benchmark模块出现禁用依赖错误的原因排查

Maven BannedDependencies 规则来源排查与错误分析

规则可能的来源

  • 继承的父POM(含企业级全局父POM)
    很多团队或公司会维护统一的父POM,里面预配置了代码规范、依赖管控这类enforcer规则。你的项目根pom可能继承了这类外部父POM,而非仅项目内的pom文件。

    • 排查方式:查看根pom的<parent>节点,逐层追踪顶层父POM的配置;或者直接执行mvn help:effective-pom -pl benchmark -am生成benchmark模块的有效POM,搜索BannedDependencies,有效POM会明确显示规则的继承来源。
  • 激活的Maven Profile
    禁用规则可能定义在某个激活的Profile中,既可能是项目根pom里的<profiles>节点,也可能是全局settings.xml(用户目录~/.m2/settings.xml或Maven安装目录conf/settings.xml)里的Profile配置。

    • 排查方式:先检查项目内的Profile,再查看全局settings文件;也可以通过mvn help:active-profiles查看当前激活的Profile,再针对性检查对应配置。
  • 全局Maven插件配置
    Maven允许在settings.xml的<plugins>节点中全局配置插件规则,有可能maven-enforcer-plugin的禁用规则是在这里定义的。

    • 排查方式:检查用户级和系统级的settings.xml文件,查找maven-enforcer-plugin的相关配置。

错误原因分析

  • 虽然commons-logging是backend模块通过sendgrid-java引入的,但benchmark模块大概率间接依赖了backend(比如做基准测试需要调用backend的代码),导致commons-logging被引入到benchmark的依赖树中,触发了禁用规则。
  • 根pom的版本管理只是锁定依赖版本,无法阻止依赖被引入,只要依赖树中出现了被禁用的依赖,enforcer插件就会抛出警告/错误。

可选解决方案(替代直接skip)

如果不想全局跳过enforcer检查,可以在benchmark模块的pom中覆盖规则,移除对commons-logging的禁用:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <executions>
        <execution>
          <id>enforce-banned-deps</id>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <bannedDependencies>
                <excludes>
                  <!-- 保留其他禁用规则,仅移除commons-logging的限制 -->
                  <exclude>!commons-logging:commons-logging</exclude>
                </excludes>
              </bannedDependencies>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 03:23:14