I want a program I'm building to be able to report its own version at runtime (e.g. scala myprog.jar --version
). Traditionally in a maven project, I'd use resource filtering (pom.xml -> file.properties -> read value at runtime). I know there's sbt-filter-plugin to emulate this functionality, but I'm curious if there's a more standard / preferred / clever way of doing this in SBT.
tl;dr how can I read the version number defined in build.sbt
at runtime?
Update...
https://github.com/ritschwumm/xsbt-reflect (mentioned above) is Obsolete, but there is this cool SBT release tool that can automatically manage versions and more: https://github.com/sbt/sbt-release.
Alternatively, if you want a quick fix you can get version from manifest like this:
This value will be equal to
version
setting in your project which you set either inbuild.sbt
orBuild.scala
.Another Update ...
Buildinfo SBT plugin can generate a class with version number based on
build.sbt
:See the docs on how to enable it here: https://github.com/sbt/sbt-buildinfo/.