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 res
I ended up making the build system (I use a Makefile on top of sbt) prepare a src/main/resources/version.txt file for Scala to read.
In the Makefile:
$(RESOURCES_VERSION): build.sbt
grep "^version := " $< | cut -f2 -d\" > $@
In Scala:
val version: String = {
val src = Source.fromURL( getClass.getResource("/version.txt") )
src.getLines.next // just take the first line
}
This works for me.
It's curious that such a needed feature (I would think) is not easily available in Scala. A very simple sbt plugin just for this would be welcome.