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!
The build. sbt file defines settings for your project. You can also define your own custom settings for your project, as described in the sbt documentation. In particular, it helps to be familiar with the settings in sbt. To set a basic setting, use the := operator: confDirectory := "myConfFolder"
Create or open your sbt project. In the Project tool window, in the source root directory, locate the build. properties file and open it in the editor. In the editor explicitly specify the version of sbt that you want to use in the project.
Play is rock-solid and used by hundreds of thousands of Java and Scala developers every month. Play is still extremely relevant to today's application and web development and has a passionate and very capable community around it ensuring that it has many good years left.
Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.
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
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`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With