Is there a way to retain the SNAPSHOT suffix on build artifacts using Maven Release Plugin?

267 Views Asked by At

I am using the mvn-release-plugin in batch mode to release the artifacts to both production and lower environments. I would like the lower environments to always and push and pull from the Artifactory Snapshots repository.

By default, mvn-release-plugin removes the SNAPSHOT suffix before rolling out the artifacts (pom/jar) to the repository. I would like to tweak with behavior and actually retain the SNAPSHOT suffix for build artifacts when releasing to Artifactory Snapshots repository. Is this possible without custom scripting ?

1

There are 1 best solutions below

0
Andrey B. Panfilov On

Well, typically release pipeline looks like:

mvn release:clean release:prepare release:perform

where:

  • release:prepare is responsible for bumping project version twice (snapshot -> release and release -> snapshot), verifying that it is possible to build release version (via preparationGoals configuration), committing corresponding changes to SCM and storing information about release version in release.properties file
  • release:perform is responsible for checking out release version from SCM and deploying release artifacts (via goals configuration)

Now, our goal is to somehow influence on release pipeline to force it to deploy snapshot artifacts as well and skip(?) deploying release artifacts. The solution actually depends on what snapshot versions we are going to deploy: current or upcoming.

In case of deploying current version, everything should actually be pretty straightforward - just adding deploy lifecycle phase before maven-release-plugin goals and skipping release:perform should work:

# skipping release:perform since we do not need to deploy release artifacts
mvn clean deploy release:clean release:prepare

however, it doesn't - in my case I'm getting NPE in AbstractRewritePomsPhase#rewriteParent method, it looks like goals/steps performed by deploy lifecycle phase change maven session state which in turn prevents release:prepare goal from running smoothly. I do see two options there:

  1. issue two separate mvn commands, i.e.:
mvn clean deploy 
mvn release:clean release:prepare
  1. create orchestrating pom file, something like:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>tld.orchestrating</groupId>
    <artifactId>orchestrate</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>deploy</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>mvn</executable>
                            <commandlineArgs>clean deploy</commandlineArgs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>prepare</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>mvn</executable>
                            <commandlineArgs>release:clean release:prepare</commandlineArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

and issue something like (however, in that case maven won't prompt you for specifying release and development versions - extra setup is required):

mvn exec:exec@deploy exec:exec@prepare -f orchestrate.xml

The same applies for deploying upcoming snapshot version - we just need to swap release:clean release:prepare and deploy goals/phases, i.e. either:

mvn release:clean release:prepare
mvn clean deploy 

or

mvn exec:exec@prepare exec:exec@deploy -f orchestrate.xml