Using the Subversion buildnumber with Maven

For one of my current projects I am changing the build process for our application from Ant to Maven. I think this is becoming a quite common change nowadays (at least it’s the third project in a rather short period I am involved with this change). And although Maven has its characteristics, I am still convinced it is a good thing to do.
Now at one point in our build process we had an Ant task to fill in a version number and build number into a property file of our application. This property file is used by the application at runtime to check if the version of the application matches the version of our database objects and the version is used in the generated SOAP response messages, which makes it easier when communicating with the customer in case of problems.
But lets get back to the issue: we had this functionality in an Ant task and I wanted to do this same thing in Maven. And it appeared that this was a remarkably easy thing to do! I ran into this Maven plugin which exactly did what I wanted.
I’ll show you an example how to use it here:

  1. Install Maven2
  2. This step is obvious, I would say. For this example there are no special settings necessary in the settings.xml. Just make sure you have access to the internet if you are behind a proxy/firewalll.

  3. Create a Maven2 project
  4. I created an example project with the command :
    mvn archetype:create -DgroupId=net.pascalalma -DartifactId=VersionTest

  5. Add the project to a SVN repository
  6. To obtain the buildnumber from Subversion we have to put the project under version control. This can be done by any SVN client (I used my favourite one: TortoiseSVN)

  7. Add ‘scm’ tag to the pom.xml
  8. To give Maven access to the SVN repository you need to configure the SVN connection in the pom, like this:

  9. Add properties file to project
  10. Next step is to add the file that will contain the version and buildnumber. I created a file called ‘’ in the directory ‘src/main/resources’.
    In the property file I put:

    my.project.version = ${project.version}.${buildNumber}

Let’s see now how to add the version and buildnr to the properties file. Add to the project’s pom.xml the following:


When you now build your project with ‘mvn clean package’ for instance, the placeholders will be replaced by the corresponding values!
And here’s another example which adds the buildNumber to the manifest file of your project (in case of having a jar file as deliverable). Put the following in your project’s pom.xml:


Now when you run ‘mvn package’ it will add the buildnumber to the manifest file. More info can be found here (including an example to extract the buildNumber in your Java code from the manifest file).
You can also find lots more info (about formatting the buildnumber) at the homepage of the plugin here.
These kind of things only make me more enthousiastic about using Maven.

About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Maven and tagged . Bookmark the permalink.

3 Responses to Using the Subversion buildnumber with Maven

  1. Paul Trickey says:

    Thanks for this – I had the buildnumber being written to the manifest but it’s much easier to use in jsps etc when it’s in a resources/properties file. Thanks again.

  2. Ro says:

    Good post – but when I try to `mvn buildnumber:create` I get this error:

    The svn command failed.
    Command output:
    svn: OPTIONS of ‘’: Server certificate verification failed: issuer is not trusted (

    Any ideas?

    Thanks, Ro

  3. Pascal Alma says:

    Hi Ro,
    It seems that the client machine at which you run Maven does not have access to the subversion server via HTTPS. Is this still an issue or did you manage to solve it?

Comments are closed.