Article
Apr 17, 2025
GIT Build Number Generation
GIT Build Number Generation (GBN) is a command-line tool that automatically generates a Java source file containing Git version information (branch, commit count, commit hash, and build number) during the build process. It integrates with build scripts or IDEs like Eclipse, enabling applications to embed build metadata for version tracking and debugging.

GIT Build Number Generation
This tool generates version or build information in a source file format from a pointing local git repository, during the pre-build phase. Currently only supports Java code generation. However, can be extended to a more generic plugin-based system to support other programming languages.
Tool favors command line arguments instead of configuration files to read the parameters, this decision is to speed up the tool, as this tool may be run several times in a time slice.
You can use this in your build script in the build phase, use in Eclipse without a build script is just a use case. The policy of when to run is left to your creativity.
Usage
gbn git-repo-directory version-file-directory package-name
git-repo-directory : Absolute path to local .git directory
version-file-directory : Absolute path to the directory, to place the version source file
package-name : Java package name
eg: gbn /home/myhome/gbn/.git/home/myhome/gbn/src/com/alkber/gbn/version/com.alkber.gbn.version
” - VersionInfo.java -
package com.alkber.gbn.version;
/*
* This is an auto generated file, modifications will not persist.
* 2013/09/22 08:48:52
*/
public class VersionInfo
{
public static final String buildNumber = "master.11.71740cc";
public static final String branch = "master";
public static final String commit = "11";
public static final String version = "71740cc639811a5c4249f4344fe5e8586a7a494b";
public static final String shortVersion = "71740cc";
}
- VersionInfo.java -
It is highly advised to place .gitingore in the version-file-directory with .gitingnore content being 'VersionInfo.java'. As this file is updated frequently, it may cause git issues during commit and merge. Further to avoid git issues ignore the *class files
Simplest Use Case
In Eclipse, Goto Project->Properties->Builders, create a new builder
Location: [ path to java binary ]
eg: [ /home/myhome/bin/dk1.7.0_25/bin/java ]
Arguments: [arguments to java binary]
eg: java -jar /home/myhome/bin/gbn.jar \
/home/myhome/git/Click2Limo/.git \
/home/myhome/git/Click2Limo/Click2Limo/src/com/frooday/click2limo/version/ \
com.frooday.click2limo.version
In the refresh tab of the new builder, the setting specifies the resource ie our version source file to be refreshed whenever the tool is run.
In the Build Options tab, Enable-
Allocate Console
During Manual Build
During Auto Build
During Clean



