问题
I have a Scala/sbt project. The project's version is in the sbt Build.scala
file.
I need to have an "about" feature that gives the product version to the user. How do I read from the SBT build file from within the Scala source?
For example, given project/Build.scala:
import sbt._
object ApplicationBuild extends Build {
val appName = "foo-product"
val appVersion = "1.1.0"
}
What I'd really like is to just be able to do ApplicationBuild.appVersion
, but that doesn't seem possible.
How can this be achieved?
回答1:
You can use sbt-buildinfo plugin.
The plugin generates a BuildInfo
object, which contains information you need.
来源:https://stackoverflow.com/questions/24088273/how-to-get-project-information-from-build-in-scala-project-code