Ci Friendly Maven Plugin

Plugin helps to use CI friendly versions in maven projects https://maven.apache.org/maven-ci-friendly.html replacing the flatten-maven-plugin

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.outbrain.swinfra
ArtifactId

ArtifactId

ci-friendly-maven-plugin
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Ci Friendly Maven Plugin
Plugin helps to use CI friendly versions in maven projects https://maven.apache.org/maven-ci-friendly.html replacing the flatten-maven-plugin
Project URL

Project URL

https://github.com/outbrain/ci-friendly-maven-plugin
Source Code Management

Source Code Management

https://github.com/outbrain/ci-friendly-maven-plugin

Download ci-friendly-maven-plugin

How to add to project

<plugin>
    <groupId>com.outbrain.swinfra</groupId>
    <artifactId>ci-friendly-maven-plugin</artifactId>
    <version>1.0.3</version>
</plugin>

Dependencies

compile (10)

Group / Artifact Type Version
org.apache.maven : maven-model jar 3.2.5
org.apache.maven : maven-model-builder jar 3.2.5
org.apache.maven.shared : maven-dependency-tree jar 2.2
org.apache.maven : maven-artifact jar 3.2.5
org.apache.maven : maven-core jar 3.2.5
org.apache.maven : maven-plugin-api jar 3.5.3
org.codehaus.plexus : plexus-utils jar 3.3.0
org.apache.maven.shared : maven-artifact-transfer jar 0.9.0
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.4
org.apache.maven.plugins : maven-scm-plugin jar 1.11.2

Project Modules

There are no modules declared in this project.

ci-friendly-flatten-maven-plugin

This is the ci-friendly-flatten-maven-plugin.

Apache License V.2 Build Status Maven Central

Why another flatten plugin?

Having a large (> 350 modules) reactor with multiple daily releases, we encountered two issues:

  1. Commit history littered with maven release plugin commits.
  2. Race between committers pushing to the main branch, and the release plugin pushing its own pom changes.

When we found out about ci friendly versions, we were ecstatic - finally we can avoid having versions in poms and achieve zero commits release process!

The only problem was that the flatten plugin coupled with the resolveCiFriendliesOnly option does not work. As adherers of the unix philosophy, we decided to create a plugin that truly, really, only replaces the revision, sha and changelist properties.

Quickstart

This plugin flattens a pom by replacing ${revision}, ${sha1}, ${changelist} to values you set by passing them as args. It then writes the resulting pom to a file named .ci-friendly-pom.xml and sets it as the new reactor. For example, installing version 2.0.0:

mvn -Drevision=2.0.0 clean install

Plugin setup

   <build>
        <plugins>
          <plugin>
            <groupId>com.outbrain.swinfra</groupId>
            <artifactId>ci-friendly-flatten-maven-plugin</artifactId>
            <!--<version>INSERT LATEST VERSION HERE</version>-->
            <executions>
              <execution>
                <goals>
                  <!-- Ensure proper cleanup. Will run on clean phase-->
                  <goal>clean</goal>
                  <!-- Enable ci-friendly version resolution. Will run on process-resources phase-->
                  <goal>flatten</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
   </build>

Plugin Goals

  • ci-friendly-flatten:flatten Replaces revision, sha1, changelist, writes the resolved pom file to .ci-friendly-pom.xml and sets it as the new reactor (Default maven phase binding: process-resources).
  • ci-friendly-flatten:clean Removes any files created by ci-friendly-flatten:flatten (Default maven phase binding: clean).
  • ci-friendly-flatten:version Fetches the latest git tag, increments it and writes it to revision.txt, relies on scm configuration.
  • ci-friendly-flatten:scmTag Tags the commit with the updated version and pushes the tag, relies on scm configuration.

Installing artifacts

  1. To avoid having to type -Drevision=<version> when installing locally, define a default revision property.

      <properties>
         <revision>5.0.0-SNAPSHOT</revision>
      </properties>
    

mvn clean install

Will install all artifacts with 5.0.0-SNAPSHOT version.

  1. Provide the version with revision arg

mvn clean install -Drevision=<VERSION>

Will install all artifacts with your provided VERSION

Deploying artifacts

Same as above, just use mvn clean deploy -Drevision=<VERSION>

How we configured it ?

  1. We added ci-friendly-flatten-maven-plugin to our pom.xml.

  2. TeamCity Configuration:

    • Added a project system param system.version.

    • The project build steps:

      • Step #1 - (Maven step) Fetch the latest git tag, increment it and write the result to revision.txt. This is the version we are going to release.

        mvn ci-friendly-flatten:version

      • Step #2 - (Command line step) Set a system.version TeamCity parameter with our soon to be released version, in order to use it in the next steps

        #!/bin/bash -x
        VER_PATH="%teamcity.build.checkoutDir%/revision.txt"
        REV=`cat $VER_PATH`
        set +x
        echo "##teamcity[setParameter name='system.version' value='$REV']"
        
      • Step #3 - (Maven step) deploy

        mvn clean deploy -Drevision=%system.version%

      • Step #4 - (Maven step) Tag the current commit with the updated version and push the tag

        mvn ci-friendly-flatten:scmTag -Drevision=%system.version%

com.outbrain.swinfra

Outbrain

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0