Lean Maven Release

The Lean Maven Release (AKA Maven Release on Steroids)
Simply put to get rid of Maven Release Plugin’s repetitive and time wasting inefficient builds and multiple checkins to SCM script this process to:
mvn clean
mvn versions:set
mvn deploy
mvn scm:tag
This can be setup in both Jenkins and Team-city.  I have been able configured this within a few minutes replacing my teams Maven Release Plugin.  This is a huge time safer and more people really need to do this especially within true Continuous Delivery team or any type of setting with frequent need for builds.

Benefits

 So how big exactly was the improvement of Releases On Steroids over the Release Plugin?

See for yourself

Releases on Steroids Maven Release Plug-in
Clean/Compile/Test cycle 1 3
POM transformations 0 2
Commits 0 2
SCM revisons
1 (binary source tag)
3

See more at Axel Fontaine’s blog where I first came across this piece of treasure after manager tipped me about it.

 

A Typical Fix

Typically The following is all I ever need to add on any project to getting maven on steriods pattern working

Add the Properties

...
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.release.plugin.version>2.5</maven.release.plugin.version>
<maven.source.plugin.version>2.2.1</maven.source.plugin.version>
<maven.javadoc.plugin.version>2.9.1</maven.javadoc.plugin.version>
<maven.gpg.plugin.version>1.5</maven.gpg.plugin.version>
...

Deployment path settings

... Local deployment
<distributionManagement>
    <repository>
        <id>internal.repo</id>
        <name>Internal repo</name>
        <url>file:///${user.home}/.m2/repository/internal.local</url>
    </repository>
</distributionManagement>
...
... or Remote deployment
<distributionManagement>
    <repository>
      <uniqueVersion>false</uniqueVersion>
      <id>corp1</id>
      <name>Corporate Repository</name>
      <url>scp://repo/maven2</url>
      <layout>default</layout>
    </repository>
</distributionManagement>

Apache maven plugins

<pluinManagement>
<plugins>
...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>${maven.release.plugin.version}</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>${maven.source.plugin.version}</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>${maven.javadoc.plugin.version}</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-gpg-plugin</artifactId>
    <version>${maven.gpg.plugin.version}</version>
</plugin>
...
<plugins>
...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>

    <configuration>
        <useReleaseProfile>false</useReleaseProfile>
        <releaseProfiles>release</releaseProfiles>
        <goals>deploy</goals>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <outputDirectory>${project.build.directory}/releases/</outputDirectory>
        <descriptors>
            <descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.6.1</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>overlays</directory>
                <includes>
                    <include>**/*</include>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
    </configuration>

</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.4</version>
</plugin>
...

The Release Profile

The Maven Release profile will be infered to for the maven deploy option

<profiles>
...
    <profile>
        <id>release</id>
        <properties>
            <activatedProperties>release</activatedProperties>
        </properties>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>${maven.compiler.plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-release-plugin</artifactId>
                        <version>${maven.release.plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>${maven.source.plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>${maven.javadoc.plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>${maven.gpg.plugin.version}</version>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
...


Assemly description

And the plugin assemly description xml.  Location: src/main/assemblies/plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly>
    <id>plugin</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <useTransitiveFiltering>true</useTransitiveFiltering>
            <excludes>
            </excludes>
        </dependencySet>
    </dependencySets>
</assembly>

Note if you intend to sign the package with the GPG plugin you’ll need to further configure this for your environment. I will write a seperate blog for this later. You may skip it with the bellow:

mvn deploy -Prelease -Dgpg.skip=true

Thats It!

Summary
Article Name
Lean Maven Release
Description
The Lean Maven release (AKA Maven Release on Steroids) Simply put to get rid of Maven Release Plugin's repetitive and time wasting inefficient builds and multiple checkins to SCM script this process to: mvn clean mvn versions:set mvn deploy mvn scm:tag This can be setup in both Jenkins and Team-city. I have been able configured this within a few minutes replacing my teams Maven Release Plugin. This is a huge time safer and more people really need to do this especially within true Continuous Delivery team or any type of setting with frequent need for builds.
Author

Leave a Reply