Maven deploy "Release Note" as artifact
Requirement : Upload (deploy) an additional file (a text format release note file) along with jar/war to nexus.
Possible Solution : Use maven deploy plugin
as below:
<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>
Problems :
RELEASENOTE.MD
file is optional. The file should be deployed only if it is present. The above solution throws an error if the file is not present. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file (default) on project ...RELEASENOTE.MD not found.
*RELEASENOTE.MD
). maven deploy plugin
does not accept regex. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file (default) on project ...*RELEASENOTE.MD not found.
How can these two problems be circumvented?
Move the deployment of the release notes to its own maven profile and activate that profile only if the release notes file is present.
<profiles>
<profile>
<activation>
<file>
<exists>RELEASENOTE.MD</exists>
</file>
</activation>
<!-- deployment of release notes declarations here -->
</profile>
</profiles>
See Introduction to Build Profiles for more information.
Regarding the regex requirement you should set up a naming policy for the release notes and implement that as variable accessible by the maven build. The build helper maven plugin might be of use there.
Combining the inputs from @SpaceTrucker and @khmarbaise , came up with the following solution:
<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>
Edit
maven-deploy-plugin
within profile activation works too. However, it poses a difficulty for release/snapshot build parameterization due to its <url>
tag. build-helper-maven-plugin
is a simpler solution
Filename regex can be handled through a wrapper shell build script
上一篇: 适用于多种环境的Maven工件
下一篇: Maven将“发行说明”部署为工件