This SBT plugin allows to automatically generate two files containing information about your GIT repository at build time:
- a Scala object
- a properties file
- In your
project/plugins.sbt
addaddSbtPlugin("eu.svez" % "sbt-git-version-object" % "$PLUGIN_VERSION")
. You can find the latest version at the top of this document. - In your
build.sbt
(or full build file) addimport eu.svez.sbt.GitVersionObjectPlugin._
- the following settings to your project:
Seq( gitVersionSettings(pkg = "com.example.yourproject", filename = "YourGitVersion"): _* )
. Thepkg
parameter can be used to specify what package where you want the Scala file to be generated, whilst thefilename
parameter will determine both the Scala object name and the config file name.
You can now refer to the Version
object directly, e.g.
println("GIT revision: " + com.example.yourproject.YourGitVersion.gitHeadCommit)
The same applies to the version.conf
file.
You can find a full example of the generated files below:
YourGitVersion.scala
package com.example.yourproject
object YourGitVersion extends scala.AnyRef {
val buildDate : scala.Predef.String = { /* compiled code */ }
val gitBranch : scala.Predef.String = { /* compiled code */ }
val gitRepoIsClean : scala.Predef.String = { /* compiled code */ }
val gitHeadCommit : scala.Predef.String = { /* compiled code */ }
val gitCommitAuthor : scala.Predef.String = { /* compiled code */ }
val gitCommitDate : scala.Predef.String = { /* compiled code */ }
}
YourGitVersion.conf
build.date = "2016-08-18T15:08:38"
git.branch = "master"
git.repo-is-clean = "false"
git.head.commit = "90d2b932a40417c653853da0bd589e87c8b54f02"
git.head.commit.author = "John Doe"
git.head.commit.date = "2016-08-18T13:41:45"
This code is open source software licensed under the Apache 2.0 License.