Eclipse git plugin and a method to fetch current branch - commit id to Java code version info string

StackOverflow https://stackoverflow.com/questions/18800062

Question

I'm using git plugin for Eclipse, as do my daily build, it becomes difficult to track which version of the build from the git is been tested. Unless there is way to auto fetch the branch and commit id from the git plugin and generate a static String version information in the code during each build. Is it possible ?

I prefer not to use a git java API from my code, like say i can fetch the git information with JGit API, if i point it to a local repos, however, that is not how it should be done, as it will create issues with application deployment. Rather should be Eclipse plugin that will generate a string during the build.

Was it helpful?

Solution

The Eclipse git plugin isn't responsible for the build.

But you can customize your Java builder and add a pre-build event which will modify one of your java files with the right version string in it.

  • See "Pre-Build events in Eclipse" for adding that pre-build step,
  • and use a task like "jgit-buildnumber": a Git "build number" plugin for Maven and Ant based on JGit. That will allow you to get the right version build number string.

OTHER TIPS

I have made a tool to do what i wanted, inspired from the above pointers by @VonC

GitBuildNumberGenerator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top