18

The Maven Buildnumber plugin doesn't appear to work with GIT yet. Is there a workaround for the time being? I recently switched from SVN to GIT and have found it to be an easy transition, but this is the only thing that I don't have working presently.

Walter

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65

7 Answers7

12

I use this Maven plugin:

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

and have it filter values directly into my spring files where I can inject them into anything I want (mostly just for reporting versions at start-up / or via a REST service).

When first starting, set it up to generate the properties file so you can see everything that is available. Extremely easy to use. Love it.

young.fu.panda
  • 261
  • 2
  • 6
  • 4
    Thanks for recommending it! I'm really trying to keep it updated as new feature requests come in :-) If you have any problems feel free to ping me via github issues! // I'm the author of this plugin. – Konrad 'ktoso' Malawski Mar 25 '13 at 18:01
  • I must did something wrong. In my project https://github.com/actframework/actframework/blob/master/pom.xml, I just can't get the maven-git-commit-id-plugin working :-( – Gelin Luo Jan 30 '16 at 23:59
10

What are you trying to achieve? I have just written a blog post that describes how you can use the buildnumber-maven-plugin to add the Git SHA-1 to your project.

For the record, I used version 1.0 of the plugin, which was released in April 2011.

matsev
  • 32,104
  • 16
  • 121
  • 156
  • 2
    One hint: If you add `scm:git:git://localhost/${basedir}`, you can use the plugin in every build directory regardless of which remote SCM URL you have. This simplifies configuration a little bit. – David Georg Reichelt May 21 '15 at 10:05
  • @matsev Thank you Mattias. In the past, we have implemented a plugin themselves (and I think it is not good). This solution works for me with: maven-scm-plugin:1.9.4; buildnumber-maven-plugin:1.4; maven-jar-plugin:2.6 – Alex K Mar 09 '16 at 12:23
6

Well, there is MOJO-1199 about the buildnumber plugin and GIT support but the patches haven't been applied yet. However, it seems that Antony Stubbs did some work around this and made it available in this git mirror. Have a look at it.

Antony Stubbs
  • 13,161
  • 5
  • 35
  • 39
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    Hi guys! I have spies everywhere ;) Yes, it is weird. Seems the plugin may be essentially abandoned. Me and a [friend of mine](http://github.com/talios) are toying with the idea of publishing the fork to repo1. – Antony Stubbs Apr 26 '10 at 02:25
  • I just chatted with pgier and wsmoak on irc.codehaus.org#maven, they said if the patch applies cleanly, they'll accept in the buildnumber-maven-plugin. – Adam Monsen May 11 '10 at 15:11
  • From Antony (or Justin?) - "I use my build every day, it definitely works for me. However, yes, I noticed the failure and disabled the tests! ;) but yes, the git integration works fine. I welcome a patch to fix the integration tests". I'll try to get to this soon. I recall maven plugin integration tests being kinda hard to debug, so I'll probably ask for help on some mailing lists. – Adam Monsen May 13 '10 at 22:30
  • The issue MOJO-1199 has been marked as resolved. In case you need branch info, there's still MBUILDNUM-66. – nawroth Nov 18 '11 at 12:13
  • 1
    As from now, even given that MOJO-1199 has been marked as resolved and builnumber-maven-plugin has 1.2 version the issue is still there :( – dant3 Oct 28 '13 at 12:10
  • 1
    I've tried **1.0, 1.1, 1.2**, and **1.3** versions of the plugin and the issue mentioned in [this comment to MOJO-1199](http://jira.codehaus.org/browse/MBUILDNUM-53?focusedCommentId=230305&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-230305) still exists, which excludes using of this plugin from any build which is not on `master` branch. – diginoise Feb 10 '15 at 12:35
6

I used buildnumber-maven-plugin with git for some time. But one day our manager was unable to setup Git CLI (in win7 with non ASCII user name). It forced me to write maven plugin using JGit API without git command line. See maven-jgit-buildnumber-plugin.

alexkasko
  • 4,855
  • 1
  • 26
  • 31
  • For non standard git installs (especially Windows) this makes dealing with the build far easier. – chotchki Nov 14 '13 at 19:17
  • Thank you, Alex! I also added more features to your plugin: https://github.com/elab/jgit-buildnumber (released to Maven Central as well) – Eugen Labun Mar 10 '19 at 18:26
3

This blog post describes how to use profiles to have the buildnumber plugin work differently when in a git or svn working copy.

Obviously(*) the buildnumber created in the git repository does not contain the subversion revision number.

(*) It should be possible to include the subversion revision number in the buildnumber when working in a git repository for commits that are already pushed back to the subverion repository.

Ruben
  • 9,056
  • 6
  • 34
  • 44
3

The current version of buildNumber plugin - 1.0 - supports the Git SCM. In the version 1.1-SNAPSHOT there is a new configuration tag shortRevisionLength for getting the short git id. More details http://yevgen-fr.blogspot.com/2012/02/maven-buildnumber-plugin-short-revision.html

Yev
  • 337
  • 4
  • 19
2

I had problems with getting the ones provided above to work.

So I wrote my own, which simply executes the git describe and assigns to a property to be used in the MANIFEST.MF.

See: https://github.com/koekiebox/git-maven-plugin

Thanks.

Koekiebox
  • 5,793
  • 14
  • 53
  • 88