aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz.driver.sbt/Versioning.scala
blob: fe3a2181b36ce613eb7bb767c483bc3880d66cd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package xyz.driver.sbt

import com.typesafe.sbt.GitPlugin
import com.typesafe.sbt.SbtGit.git
import sbt.Keys._
import sbt.plugins.JvmPlugin
import sbt.{AutoPlugin, _}

object Versioning extends AutoPlugin {

  override def requires = JvmPlugin
  override def trigger  = allRequirements

  // Get version from git unless a VERSION environment variable is set
  lazy val versionSettings: Seq[Setting[_]] = sys.env.get("VERSION") match {
    case None =>
      GitPlugin.autoImport.versionWithGit ++ Seq(
        git.useGitDescribe := true, // get version from git
        git.baseVersion := "0.0.0" // this version is used for new projects without any commits
      )
    case Some(v) =>
      Seq(
        version := v
      )
  }

  override def buildSettings = versionSettings ++ Seq(
    organization := "xyz.driver"
  )

}