Maven发布插件失败:源工件被部署两次

Van*_*ran 58 java nexus maven maven-release-plugin

我们正在使用hudson上的maven发布插件并尝试自动执行发布过程.发布:准备工作正常.当我们尝试执行release:perform时,它会失败,因为它会尝试将源工件两次上传到存储库.

我试过的东西,

  1. 从超级pom中删除包含maven源插件的配置文件(不起作用)
  2. 将hudson上的目标指定为-P!attach-source release:prepare release:perform.我认为这将排除源插件被执行.(不工作).
  3. 尝试将插件阶段指定为超级pom中的一些不存在的阶段.(没有工作)
  4. 尝试将插件配置指定为forReleaseProfile为false.(猜猜是什么?也没用)

它仍然吐出这个错误.

[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Checking for pre-existing User-Agent configuration.
[INFO] [DEBUG] Adding User-Agent configuration.
[INFO] [DEBUG] not adding permissions to wagon connection
[INFO] Uploading: http://xx.xx.xx.xx:8081/nexus/content/repositories/releases//com/yyy/xxx/hhh/hhh-hhh/1.9.40/hhh-hhh-1.9.40-sources.jar
[INFO] 57K uploaded  (xxx-xxx-1.9.40-sources.jar)
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Checking for pre-existing User-Agent configuration.
[INFO] [DEBUG] Adding User-Agent configuration.
[INFO] [DEBUG] not adding permissions to wagon connection
[INFO] Uploading: http://xx.xxx.xx.xx:8081/nexus/content/repositories/releases//com/xxx/xxxx/xxx/xxx-xxx/1.9.40/xxx-xxx-1.9.40-sources.jar
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Error deploying artifact: Authorization failed: Access denied to: http://xx.xxx.xx.xx:8081/nexus/content/repositories/releases/com/xxx/xxx/xxx/xxx-config/1.9.40/xxx-xxx-1.9.40-sources.jar
Run Code Online (Sandbox Code Playgroud)

任何有关这方面的帮助将非常感谢.

Bae*_*Bae 68

试试跑步mvn -Prelease-profile help:effective-pom.你会发现你有两个执行部分maven-source-plugin

输出看起来像这样:

    <plugin>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.0.4</version>
      <executions>
        <execution>
          <id>attach-sources</id>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
        <execution>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
Run Code Online (Sandbox Code Playgroud)

要解决此问题,请查找您使用过的所有位置maven-source-plugin,并确保使用"id"attach-sources以使其与发布配置文件相同.然后这些部分将合并.

最佳实践说,为了获得一致性,您需要在build> pluginManagement中的项目的根POM中配置它,而不是在您的子poms中.在子pom中,您只需在build> plugins中指定要使用maven-source-plugin,但不提供执行.

在房间pom.xml:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <!-- This id must match the -Prelease-profile id value or else sources will be "uploaded" twice, which causes Nexus to fail -->
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>    
  </pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)

在子pom.xml中:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
    </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

  • 我发现“attach-sources”仍然被称为具有相同配置的交换机。有人知道吗?`第 640 行:[信息] [调试] 目标:org.apache.maven.plugins:maven-source-plugin:3.0.1:jar (attach-sources)` `第 660 行:[信息] [调试] 目标:org .apache.maven.plugins:maven-source-plugin:3.0.1:jar-no-fork (附加源)` (3认同)
  • 类似的博文:http://blog.peterlynch.ca/2010/05/maven-how-to-prevent-generate-sources.html (2认同)
  • 有同样的问题。解决了。我的pom文件具有以jar-no-fork为目标的maven-source-plugin,但是maven根pom文件具有以jar为目标的相同插件。因此,生成的有效pom具有两个目标。这将导致重复尝试推送sources.jar。一旦我删除了pom中的jar-no-fork目标,默认的jar目标就是仅有的一个,构建成功。对于我的用法,它是罐子还是罐子无叉子都没有关系。 (2认同)

chr*_*own 26

我知道这个问题已经过时了,但谷歌今天打了#1,所以我会添加适合最近版本的maven 3的答案.

症状是在使用某些版本的maven 3进行发布构建时,源和javadoc jar被部署两次.如果您使用maven将工件部署到Sonatype Nexus存储库,该存储库仅允许上传一次发布工件(是完全合理的行为),当第二次上传尝试被拒绝时,构建失败.哎呀!

Maven版本3.2.3至3.3.9有错误 - 请参阅https://issues.apache.org/jira/browse/MNG-5868https://issues.apache.org/jira/browse/MNG-5939.这些版本在执行发布时会生成并部署两次源和javadoc jar.

如果我正确地阅读了Maven问题跟踪器,那么在撰写本文时,这些错误都没有安排进行修复(烧毁的3.4.0版本可能会影响这些).

我的简单解决方法是回到Maven版本3.2.1,而不是对我的pom进行复杂的调整.

  • 2020 年 6 月更新:应该在 Maven 版本 3.7.0 中修复 (3认同)
  • 在严重的头部撞墙之后......是的,这是唯一可行的解​​决方案,THX!由于我们仍然锁定 JDK 6 一段时间,并且 Maven 3.3.+ 需要 Java 7,回滚到 Maven 3.2.2 是唯一可接受的选择。 (2认同)

Paŭ*_*ann 7

刚刚遇到同样的问题,我分析了一下.mvn release:perform评估release.properties文件,然后检出临时目录中的标记并调用类似的东西

/usr/bin/mvn -D maven.repo.local=... -s /tmp/release-settings5747060794.xml
    -D performRelease=true -P set-envs,maven,set-envs deploy
Run Code Online (Sandbox Code Playgroud)

我试图重现这一点 - 手动检查生成的标签release:prepare并调用它:

mvn -D performRelease=true -P set-envs,maven,set-envs deploy
Run Code Online (Sandbox Code Playgroud)

我得到了相同的结果:它试图上传-sources.jar两次.

正如注释中的qualidafial所指出的那样,设置performRelease=false会忽略同一文件的两个附件之一.

我真的不知道部署插件(或任何其他插件)如何使用此属性.

我们可以将此参数作为配置提供给maven-relase-plugin:

<build>
    <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <useReleaseProfile>false</useReleaseProfile>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我现在将<useReleaseProfile>false</useReleaseProfile>行添加到所有POM中,看起来现在发布没有错误消息.


Tob*_*ous 5

我一直在努力解决这个问题,终于能够在我们的基础设施中解决它。这里的答案对我没有帮助,因为我们没有多次执行源插件目标,而且配置对我们来说似乎很好。

我们错过的是将源插件的执行绑定到一个阶段。扩展 Bae 的示例,包括<phase>install</phase>执行的行为我们解决了问题:

<plugin>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.0.4</version>
  <executions>
    <execution>
      <id>attach-sources</id>
      <phase>install</phase>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我怀疑的解决办法在于这个答案在这里; 不同的插件似乎正在调用 jar 目标/附加源执行。通过将我们的执行绑定到某个阶段,我们强制我们的插件只在这个阶段运行。


Eri*_*icS 5

这发生在我跑步时

mvn install deploy
Run Code Online (Sandbox Code Playgroud)

我通过运行避免了这个问题

mvn deploy
Run Code Online (Sandbox Code Playgroud)

(这意味着安装)。在我的例子中,只有一个工件被尝试上传两次,这是一个次要工件(maven-jar-plugin 设置为除了由 default-jar 执行构建的 jar 之外,还构建一个辅助 jar)。