Maven 将“发行说明”部署为工件

伽玛

要求:上传(部署)一个附加文件(文本格式的发行说明文件)以及 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文件是可选的。仅当文件存在时才应部署该文件。如果文件不存在,上述解决方案会引发错误。

[错误] 无法执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file (default) on project ...\RELEASENOTE.MD not found。

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

[错误] 无法执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file (default) on project ...*RELEASENOTE.MD not found。

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

伽玛

结合来自@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在配置文件激活中也有效。然而,由于它的<url>标签,它给发布/快照构建参数化带来了困难build-helper-maven-plugin是一个更简单的解决方案

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章