8

Currently, my Java applications have the same version on every build. I am using Maven, but I am not sure how to set up the workflow to add a version to the application on each build.

I imagine this works with my version control system? I am using git, does this mean I need git tags?

Thanks for any insights, I know it's a big question, but I am not sure where to get started.

Zippy Zeppoli
  • 5,847
  • 4
  • 18
  • 16
  • 1
    A java application does not have inherent notion of version. Where is the version -- which currently does not change -- coming from? – Miserable Variable Oct 31 '12 at 00:31
  • 1
    There is probably a properties or manifest file that you need to update during your build. – Thilo Oct 31 '12 at 00:40
  • Related http://stackoverflow.com/questions/690419/build-and-version-numbering-for-java-projects-ant-cvs-hudson – andersoj Oct 31 '12 at 00:50
  • 1
    Also see [Setting Package Version Information](http://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html) for properties in the manifest that can be retrieved at run-time. – Andrew Thompson Oct 31 '12 at 01:55

3 Answers3

6

You start by setting your version to, for example, 1-SNAPSHOT.

Then you use the maven-release-plugin to release early and often.

In the interim, each snapshot gets a unique timestamp.

If you want to apply a version that isn't the official maven version, see the buildnumber-maven-plugin.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
3

I use this Maven plugin:

https://github.com/ktoso/maven-git-commit-id-plugin

and get it to generate a git.properties file for me. This includes the commit id, comments, etc.

From there, you can do whatever you like. I have a properties page in my webapp that simply iterates over everything in git.properties. Works for me.

millhouse
  • 9,817
  • 4
  • 32
  • 40
0

You can use maven POM file to define versions. Here is an explanation.

Also you can update versions using this.

pedjaradenkovic
  • 241
  • 1
  • 9