【问题标题】:Maven deploy "Release Note" as artifactMaven 将“发行说明”部署为工件
【发布时间】:2017-06-27 07:11:04
【问题描述】:

要求:将附加文件(文本格式的发行说明文件)连同 jar/war 上传(部署)到 nexus。

可能的解决方案:使用maven deploy plugin,如下:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <executions>
                <execution>
                    <phase>deploy</phase>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <configuration>
                        <packaging>RELEASENOTE.MD</packaging>
                        <generatePom>false</generatePom>
                        <url>${project.distributionManagement.repository.url}</url>
                        <artifactId>${project.artifactId}</artifactId>
                        <groupId>${project.groupId}</groupId>
                        <version>${project.version}</version>
                        <file>RELEASENOTE.MD</file>
                    </configuration>
                </execution>
            </executions>
        </plugin>

问题

  1. RELEASENOTE.MD 文件是可选的。仅当文件存在时才应部署该文件。如果文件不存在,上述解决方案会引发错误。

[ERROR] 未能执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file (默认) 在项目中...\RELEASENOTE.MD 未找到。

  1. 需要通过正则表达式指定文件名的选项(例如:*RELEASENOTE.MD)。 maven deploy plugin 不接受正则表达式。

[ERROR] 未能执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file (默认) 在项目中...*RELEASENOTE.MD 未找到。

如何规避这两​​个问题?

【问题讨论】:

  • 为什么不在版本控制中简单地签入该工件?还是在构建过程中通过 build-helper-maven-plugin 添加?
  • 是的,它将被签入到版本控制中。但它是可选的。并非所有的罐子都会有发行说明。因此,如果文件不存在,插件不应尝试部署该文件。
  • 创建 jar 的相应项目应该将发行说明附加到项目而不是部署插件。顺便说一句:为什么要将发行说明放入存储库而不是生成的站点?
  • 发行说明是 repo 中的静态文件还是生成的(由 jenkins,例如)是第二步。如果文件存在(并且仅当文件存在)的问题,我们如何将它部署到nexus。
  • 如前所述,使用 build-helper-maven-plugin 将其作为补充资源添加到 jar 文件的原始构建中……maven-deploy-plugin 不是正确的方法去吧。

标签: java maven deployment devops


【解决方案1】:

将发行说明的部署移动到其自己的 Maven 配置文件中,并仅在发行说明文件存在时激活该配置文件。

<profiles>
  <profile>
    <activation>
      <file>
        <exists>RELEASENOTE.MD</exists>
      </file>
    </activation>
    <!-- deployment of release notes declarations here -->
  </profile>
</profiles>

更多信息请参见Introduction to Build Profiles

关于正则表达式要求,您应该为发行说明设置命名策略,并将其实现为 maven 构建可访问的变量。 build helper maven plugin 可能在那里有用。

【讨论】:

    【解决方案2】:

    结合来自 @SpaceTrucker@khmarbaise 的输入,得出以下解决方案:

    <profiles>
        <profile>
            <id>add-release-note</id>
            <activation>
                <file><exists>RELEASENOTE.MD</exists></file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>attach-artifacts</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>RELEASENOTE.MD</file>
                                            <type>MD</type>
                                            <classifier>RELEASENOTE</classifier>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    

    编辑

    • maven-deploy-plugin 在配置文件激活中也有效。但是,由于其&lt;url&gt; 标签,它给发布/快照构建参数化带来了困难。 build-helper-maven-plugin 是一个更简单的解决方案

    • 文件名正则表达式可以通过包装外壳构建脚本处理

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多