Version Scala SBT project using git tags
30 of May, 2017
Unfortunately it has few near fatal flaws:
- You would have to remember to change version number in build file once it’s “ready”;
- If you use git (you should), then you would probably have to maintain version number in few places (and try to keep it in sync too);
- The command to get the only version number in sbt is quite ugly and verbose (ok, maybe this one is not that fatal):
Wouldn’t it be cool if SBT would be able to determine version number from git tags?
Thankfully there is a plugin just for that and it’s called sbt-git.
is very trivial and is exactly what you would need to do for most of other sbt plugins.
Add plugin dependency at
Enable it in
Git tag version matching rules
- It requires tags to start with “v” (by default, this can be configured otherwise);
- When there are no matching tags or when current commit is not tagged, then it will use full commit sha like this one:
- When there is matching tag, then it will be used as a version (minus the “v”) -
- When current commit is tagged, but there are changes to tracked files, then it will use “-SNAPSHOT” suffix, like
There are other version matching rules and example matching customisation in original documentation (for instance, to match any tag starting with a number, not requiring the “v” prefix anymore).
So is it any good?
Sbt-git is great in context of continuous delivery and automation:
- You don’t have to change code to tag version number;
- With sbt-git the git tags become the only version to maintain - no discrepancies;
- Virtually any ci environment supports git, it’s easy to automate and there are tons of examples.
The plugin is well maintained and worked flawlessly in my case - highly recommended.comments powered by Disqus