Reputation: 539
I've been seeing a bunch of questions about how to read a version from build.sbt, and there have been a lot of work-arounds provided for how to point build.sbt to conf/application.conf and have the version specified in conf/application.conf instead.
I have a Configuration object that needs to get in the version. I currently have it set up like this (How get application version in play framework and build.sbt), where the Configuration objects from application.conf. However, I'd still like to get it directly from build.sbt. How can I do that? Should I perhaps run a bash command on the build.sbt file to get the version from there? Any suggestions?
Thanks!
Upvotes: 6
Views: 1483
Reputation: 876
We managed to get information via build-info, here's some detail configuration.
Add plugins (we also include sbt-git since we want git version as well) into project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.4")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.5.0")
Configure plugins in build.sbt
enablePlugins(BuildInfoPlugin)
enablePlugins(GitVersioning)
buildInfoKeys := Seq[BuildInfoKey](organization, name, version, BuildInfoKey.action("gitVersion") {
git.formattedShaVersion.?.value.getOrElse(Some("Unknown")).getOrElse("Unknown") +"@"+ git.formattedDateVersion.?.value.getOrElse("")
})
buildInfoPackage := "version"
Within views (*.html.scala), display those info simply by
Version @version.BuildInfo.version - build @version.BuildInfo.gitVersion
Or you can just using all values from BuildInfo in your java or scala code, by calling version.BuildInfo.XX
Upvotes: 7
Reputation: 55798
Maybe not quite what you want but some time ago I used such workaround (I needed version for additional deployment steps): I created file like app-version.cfg
in the main app directory, so I could use it within build.sbt
like:
version := scala.io.Source.fromFile("app-version.cfg").mkString
and in Unix bash:
version=`cat app-version.cfg`
Upvotes: 2