/sbt-git-version-object

SBT plugin to automatically generate Git version information

Primary LanguageScalaApache License 2.0Apache-2.0

sbt-git-version-object

Build Status Download

This SBT plugin allows to automatically generate two files containing information about your GIT repository at build time:

  1. a Scala object
  2. a properties file

Setup

  1. In your project/plugins.sbt add addSbtPlugin("eu.svez" % "sbt-git-version-object" % "$PLUGIN_VERSION"). You can find the latest version at the top of this document.
  2. In your build.sbt (or full build file) add
    • import eu.svez.sbt.GitVersionObjectPlugin._
    • the following settings to your project: Seq( gitVersionSettings(pkg = "com.example.yourproject", filename = "YourGitVersion"): _* ) . The pkg parameter can be used to specify what package where you want the Scala file to be generated, whilst the filename parameter will determine both the Scala object name and the config file name.

Usage

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"

License

This code is open source software licensed under the Apache 2.0 License.