Commit timestamp in Maven version using jgitver

435 views Asked by At

I'm evaluating the jgitver Maven extension for calculating artefact versions from git metadata.

jgitver provides the commit datetime in a property called jgitver.head_commit_datetime, but I can't figure out how to include the timestamp in the version string.

Can anyone help?

2

There are 2 answers

0
Matthieu BROUILLARD On BEST ANSWER

@otto.poellath, you can use the configuration property useGitCommitTimestamp and set it to true ; it is only available in the non maven mode of jgitver as it is a bit clashing with strict maven SNAPSHOTs.

So if you have your .mvn/jgitver.config.xml config file that contains something like the following it will work:

<mavenLike>false</mavenLike>
<useGitCommitTimestamp>true</useGitCommitTimestamp>

Here is an output of a local mvn validate on jgitver-maven-plugin itself using such a configuration

H:\jgitver-maven-plugin>mvn validate
[INFO] using jgitver configuration file: H:\jgitver-maven-plugin\.mvn\jgitver.config.xml
[INFO] Scanning for projects...
[INFO] Using jgitver-maven-plugin [1.3.0] (sha1: ef8eec9f820d662e63a84f1210c377183e450cbd)
[INFO] jgitver-maven-plugin is about to change project(s) version(s)
[INFO]     fr.brouillard.oss::jgitver-maven-plugin::0 -> 1.3.1-20180710075533-integration
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jgitver Maven Plugin 1.3.1-20180710075533-integration
[INFO] ------------------------------------------------------------------------
...
3
Niels Bech Nielsen On

Thanks to maven lazy evaluation, you can provide them into the build using the versions plugin, something like:

mvn jgitver versions:set -DnewVersion=1.0.\${jgitver.head_commit_datetime} versions.commit

Try that and let me know.

It basically pass the property onto the versions:set plugin, and this will rewrite all pom files to the given new version.