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

未在pom.xml引入maven-source-plugin却执行失败,本地正常远程任务报错求助

解决Maven构建在Electric Commender中出现的重复附件与maven-source-plugin报错问题

问题现象

本地Maven构建可正常完成,但在Electric Commender(EC)执行构建任务时,抛出以下两个错误:

[ERROR] We have duplicated artifacts attached.
Failed to execute goal org.apache.maven.plugins:maven-source-plugin:3.3.0:jar-no-fork

注意:项目pom.xml中并未显式引入maven-source-plugin依赖。

排查与解决步骤

1. 检查生效POM中的隐式插件绑定

EC环境的Maven配置(如全局settings.xml、继承的父POM)可能自动绑定了maven-source-plugin,而本地环境无此配置,导致构建行为不一致。

  • 执行命令查看实际生效的POM:
    mvn help:effective-pom
    
  • 若发现source-plugin被自动绑定,可在项目pom.xml中显式禁用该插件的执行:
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <executions>
            <execution>
              <id>attach-sources</id>
              <phase>none</phase>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    

2. 排查EC任务的额外构建配置

EC任务可能单独配置了触发源码打包的步骤,与隐式触发的插件执行冲突,导致重复附件错误。

  • 检查EC任务的构建参数,确认是否存在额外触发source-plugin的配置(如单独添加了源码打包步骤)。
  • 在EC构建命令中添加参数,强制跳过source-plugin执行:
    mvn clean install -Dmaven.source.skip=true
    

3. 处理插件版本冲突

即使未显式引入,项目依赖可能间接引入了不同版本的maven-source-plugin,引发版本冲突导致报错。

  • 执行命令查看间接依赖的source-plugin版本:
    mvn dependency:tree | grep source-plugin
    
  • 显式在pom.xml中管理source-plugin的版本与执行逻辑,避免冲突:
    <build>
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
                <phase>package</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 05:25:10