Maven 发布插件失败:源工件被部署两次 [英] Maven release plugin fails : source artifacts getting deployed twice

查看:40
本文介绍了Maven 发布插件失败:源工件被部署两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我尝试过的东西,

  1. 从超级 pom 中删除包含 maven 源插件的配置文件(不起作用)
  2. 将 hudson 的发布目标指定为 -P!attach-source release:prepare release:perform.我认为这将排除源插件的执行.(没有用).
  3. 尝试将插件阶段指定为超级 pom 中某个不存在的阶段.(无效)
  4. 尝试指定插件配置,forReleaseProfile 为 false.(你猜怎么着??也没有用)

它仍然吐出这个错误.

[INFO] [DEBUG] 从协议 http 的默认映射中使用 Wagon 实现轻量级[INFO] [DEBUG] 从协议 http 的默认映射中使用 Wagon 实现轻量级[信息] [调试] 检查预先存在的用户代理配置.[信息] [调试] 添加用户代理配置.[INFO] [DEBUG] 未添加货车连接权限[信息] 上传: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 上传 (xxx-xxx-1.9.40-sources.jar)[INFO] [DEBUG] 从协议 http 的默认映射中使用 Wagon 实现轻量级[INFO] [DEBUG] 从协议 http 的默认映射中使用 Wagon 实现轻量级[信息] [调试] 检查预先存在的用户代理配置.[信息] [调试] 添加用户代理配置.[INFO] [DEBUG] 未添加货车连接权限[信息] 上传: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] 从协议 http 的默认映射中使用 Wagon 实现轻量级[信息] [信息] -------------------------------------------------------------------------[信息] [错误] 构建错误[信息] [信息] -------------------------------------------------------------------------[INFO] [INFO] 部署工件时出错:授权失败:访问被拒绝: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

对此的任何帮助将不胜感激.

解决方案

尝试运行 mvn -Prelease-profile help:effective-pom.你会发现maven-source-plugin

有两个执行部分

输出将如下所示:

<块引用>

 <插件>

 maven-source-plugin<version>2.0.4</version><执行><执行><id>附加源</id><目标><goal>jar</goal></目标></执行><执行><目标><goal>jar</goal></目标></执行></执行></插件>

要解决此问题,请找到您使用过 maven-source-plugin 的所有地方,并确保您使用了id".附加源,以便它与发布配置文件相同.然后这些部分将被合并.

最佳实践表明,为了获得一致性,您需要在 build > 项目的根 POM 中进行配置.pluginManagement 和 NOT 在您的子 poms 中.在子 pom 中,您只需在 build > 中指定您想使用 maven-source-plugin 但不提供执行的插件.

在根 pom.xml 中:

<插件管理><插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><执行><执行><!-- 此 id 必须与 -Prelease-profile id 值匹配,否则源将被上传";两次,这会导致 Nexus 失败 --><id>附加源</id><目标><goal>jar</goal></目标></执行></执行></插件></插件></pluginManagement></build>

在子 pom.xml 中:

<插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId></插件></插件></build>

We are using the maven release plugin on hudson and trying to automate the release process. The release:prepare works fine. When we try to do the release:perform , it fails because it tries to upload a source artifact twice to the repository.

Things that I tried,

  1. removing the profile which does include the maven source plugin from the super pom ( did not work)
  2. specifying the goals on hudson for release as -P!attach-source release:prepare release:perform. Which I thought will exclude the source plugin from getting executed. (did not work).
  3. tried specifying the plugin phase to some non existent phase in the super pom.(Did not work)
  4. tried specifying the plugin configuration, forReleaseProfile as false. ( guess what?? Did not work too)

It still spits out this error.

[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

Any help regarding this will be really appreciated.

解决方案

Try running mvn -Prelease-profile help:effective-pom. You will find that you have two execution sections for maven-source-plugin

The output will look something like this:

    <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>

To fix this problem, find everywhere you have used maven-source-plugin and make sure that you use the "id" attach-sources so that it is the same as the release profile. Then these sections will be merged.

Best practice says that to get consistency you need to configure this in the root POM of your project in build > pluginManagement and NOT in your child poms. In the child pom you just specify in build > plugins that you want to use maven-source-plugin but you provide no executions.

In the root 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>

In the child pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
    </plugin>
  </plugins>
</build>

这篇关于Maven 发布插件失败:源工件被部署两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆