Reputation: 11427
What is the best way to store the version of my application?
I use Git tagging to store a semantic version number in the Git repository. But I also want to print out the version number to the user of the program (f.ex. when a user calls ./myprogram --version
). So I also had to manually change a String constant in my Java source code for every new version.
Is there a smarter way to keep the version numbers in the Git repository and the source code in sync?
Upvotes: 1
Views: 598
Reputation: 15189
In our project we use the git-commit-id-plugin for maven. You can generate something that can be read at runtime by your program, e.g., a Java class that contains static fields or a properties file that is read.
If you don't use maven, there surely is a plugin for your build tool or, at the very least, the possibility to somehow call git describe
(as suggested by others).
Upvotes: 1
Reputation:
You can get the current tag from git using
git describe [--abbrev=0] > localFileForTag
If you put that line into a script and run that script during the build process, you can store the current tag in a local file. Your program just has to read and print the file content.
Upvotes: 2