jgitver - maven plugin: Derive version from Git commit, including Git SHA8 String and SNAPSHOT marker

798 views Asked by At

I'll try to keep this question short and simple:

with the jgitver maven plugin I can easily create versions from Git tags. The ${jgitver.calculated_version} variable that I can use in my .pom file will, by default, behave like this:

  1. set Git tag "v1.0.0"
    version: 1.0.0
  2. do Git commit
    version: 1.0.1-SNAPSHOT

Is it possible to (and if so how can I) include the commit hash in the version number, like so?

  1. set Git tag "v1.0.0"
    version: 1.0.0-162ad57
  2. do Git commit
    version: 1.0.1-ff8cb8a-SNAPSHOT

The important part is that version numbers from simple (not tagged) commits also end with "SNAPSHOT".

1

There are 1 answers

3
Matthieu BROUILLARD On

Yes it is possible.

in the .mvn/jgitver.config.xml file set the property useGitCommitId to true. You can also define the expected length of the SHA1 using gitCommitIdLength

something like:

<useGitCommitId>true</useGitCommitId>
<gitCommitIdLength>8</gitCommitIdLength>  <!-- between [8,40] -->