Saturday, June 27, 2009

Consistent SVN branch and tag names for maven projects

When using maven together with subversion (SVN), it is good to have a naming strategy for your branches and tags which is consistent with the maven versions of your projects (in the pom.xml files). A consistent naming strategy makes it trivial to know which version of a maven project can be found where in the SVN repository (and vice versa), and it prevents possible version conflicts between maven projects when for example branching twice from the same starting point.

We designed a simple scheme at work which suits us well. I thought I might as well share it, you might find it useful.
  • In principle, we have a X.Y.Z numbering scheme for all our maven projects (but having only one or two numbers would be possible as well); for example someproject-3.4.4.
  • All main development happens on trunk (for the "current" release). A maven project on trunk thus has a version number X.Y.Z-SNAPSHOT; for example someproject-3.4.5-SNAPSHOT.
  • When releasing a maven project, the word "SNAPSHOT" is removed from the version; for example someproject-3.4.5. On trunk, development continues with the next SNAPSHOT version; for example someproject-3.4.6-SNAPSHOT (or perhaps 3.5.0-SNAPSHOT or even 4.0.0-SNAPSHOT).
  • A released project is tagged in SVN as ${artifactId}-${version}; for example http://svnserver/svnrepo/tags/someproject-3.4.5.
  • A branch (for fixes in "old" releases) is always taken starting from a tag. Branching a project tagged with version X.Y.Z results in a branch SVN directory called X.Y.Z.1.x; for example http://svnserver/svnrepo/branches/someproject- (the 1 means "first branch", the x indicates that that is the only part of the version which changes in this branch during the lifetime of the branched project).
  • If another branch is taken from the same tag, it becomes X.Y.Z.2.x etc (This actually corresponds to how CVS does it: branching introduces two extra numbers); for example http://svnserver/svnrepo/branches/someproject-
  • The version of the maven project in a branch follows this naming strategy; for example the maven version of the project in .../branches/someproject- is initially
  • Releasing from a branch results in a tag with 5 numbers; for example the first release would be someproject- and the branch would continue with
  • Branching on a branch is also possible, just add another two numbers; for example X.Y.Z.1.2.1.x (first branch of the second release from that first branch of project with version X.Y.Z). In our case, this has been necessary only once though.
I guess we aren't the first team to invent this, but I have never seen it written down for the SVN/maven combination like this.


Anonymous said...

Interesting blog as for me. I'd like to read a bit more about that topic. Thnx for posting that data.
Sexy Lady
Escorts UK

Anonymous said...

Thanks for sharing this strategy. It was useful for me as I am experiencing a similar problem and this has given me some ideas.

Anonymous said...

I don't understand role of x in the naming of branch. For example if I want to create branch for my project having tag artifactId-1.1.1 What it will be?