Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Maven way for automatic project versions when doing continuous delivery?

I have a web application where we deploy to production whenever a feature is ready, sometimes that can be a couple of times a day, sometimes it can be a couple of weeks between releases.

Currently, we don't increment our version numbers for our project, and everything has been sitting at version 0.0.1-SNAPSHOT for well over a year. I am wondering what is the Maven way for doing continuous delivery for a web apps. It seems overkill to bump up the version number on every commit, and never bumping the version number like we are doing now, also seems wrong.

What is the recommend best practice for this type of Maven usage?

The problem is actually a two-fold one:

  • Advancing project version number in individual pom.xml file (and there can be many).
  • Updating version number in all dependent components to use latest ones of each other.
like image 504
ams Avatar asked Aug 27 '13 02:08

ams


People also ask

Why Continuous Integration Services is used with Maven?

The main benefit of Continuous Integration is the ability to flag errors as they are introduced into a system instead of waiting multiple days for test failures and critical errors to be identified during the QA cycle.

Is Maven a continuous integration server?

A maven is a build tool designed to manage dependencies and the software lifecycle. It is also designed to work with plugins that allow users to add other tasks to the standard compile, test, package, install, deploy tasks. Jenkins is designed for the purpose of implementing Continuous Integration (CI).

How are the Maven projects maintained?

Much of the project management and build related tasks are maintained by Maven plugins. Developers can build any given Maven project without the need to understand how the individual plugins work. We will discuss Maven Plugins in detail in the later chapters.


2 Answers

I recommend the following presentation that discusses the practical realities of doing continuous delivery with Maven:

  • You tube presentation on CD with Maven
  • Slides

The key takeaway is each build is a potential release, so don't use snapshots.

like image 113
Mark O'Connor Avatar answered Sep 19 '22 21:09

Mark O'Connor


This is my summary based on the video linked by Mark O'Connor's answer.

  • The solution requires a DVCS like git and a CI server like Jenkins.
  • Don't use snapshot builds in the Continuous Delivery pipeline and don't use the maven release plugin.
  • Snapshot versions such as 1.0-SNAPSHOT are turned into real versions such as 1.0.buildNumber where the buildNumber is the Jenkins job number.

Algorithm steps:

  1. Jenkins clones the git repo with the source code, and say the source code has version 1.0-SNAPSHOT
  2. Jenkins creates a git branch called 1.0.JENKINS-JOB-NUMBER so the snapshot version is turned into a real version 1.0.124
  3. Jenkins invokes the maven versions plugin to change the version number in the pom.xml files from 1.0-SNAPSHOT to 1.0.JENKINS-JOB-NUMBER
  4. Jenkins invokes mvn install
  5. If the mvn install is a success then Jenkins will commit the branch 1.0.JENKINS-JOB-NUMBER and a real non-snapshot version is created with a proper tag in git to reproduce later. If the mvn install fails then Jenkins will just delete the newly created branch and fail the build.

I highly recommend the video linked from Mark's answer.

like image 27
ams Avatar answered Sep 21 '22 21:09

ams