Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
I know this because build.sbt knows this.
branch: master



I know this because build.sbt knows this.

sbt-buildinfo generates Scala source from your build definitions.

Latest Stable

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.2")

For sbt 0.12, see 0.2.5.


Add the following in your build.sbt:


sourceGenerators in Compile <+= buildInfo

buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion)

buildInfoPackage := "hello"

(Note: in version 0.1.2, this was Seq[Scoped] instead!)

Alternatively, if you are using Build.scala, add the plugin to your build as follows:

import sbtbuildinfo.Plugin._

// ...more code here

lazy val myProject = Project(
    id = "helloworld",
    base = file(".")
      buildInfoSettings ++
          sourceGenerators in Compile <+= buildInfo,
          buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
          buildInfoPackage := "hello"
      ) ++

When you reload the settings and compile, this generates the following:

package hello

/** This object was generated by sbt-buildinfo. */
case object BuildInfo {
  /** The value is "helloworld". */
  val name = "helloworld"
  /** The value is "0.1-SNAPSHOT". */
  val version = "0.1-SNAPSHOT"
  /** The value is "2.10.3". */
  val scalaVersion = "2.10.3"
  /** The value is "0.13.2". */
  val sbtVersion = "0.13.2"
  override val toString = "name: %s, version: %s, scalaVersion: %s, sbtVersion: %s" format (name, version, scalaVersion, sbtVersion)

  val toMap = Map[String, Any](
    "name" -> name,
    "version" -> version,
    "scalaVersion" -> scalaVersion,
    "sbtVersion" -> sbtVersion)

Customize buildInfoKeys by adding whatever keys you want to have in BuildInfo. You can use to change the generated field name and value, add new fields with tuples, or add new fields with values computed at build-time:

buildInfoKeys ++= Seq[BuildInfoKey](
  libraryDependencies in Test, { case (k, v) => "project" + k.capitalize -> v.capitalize },
  "custom" -> 1234, // computed at project load time
  BuildInfoKey.action("buildTime") {
  } // re-computed each time at compile

This generates:

  /** The value is Seq("Sonatype Public:"). */
  val resolvers = Seq("Sonatype Public:")
  /** The value is Seq("org.scala-lang:scala-library:2.9.1", ...). */
  val test_libraryDependencies = Seq("org.scala-lang:scala-library:2.9.1", ...)
  /** The value is "Helloworld". */
  val projectName = "Helloworld"
  /** The value is 1234. */
  val custom = 1234
  /** The value is 1346906092160L. */
  val buildTime = 1346906092160L

Tasks can be added only if they do not depend on sourceGenerators. Otherwise, it will cause an infinite loop.

Here's how to change the generated object name:

buildInfoObject := "Info"

This changes the generated object name to object Info. Changing the object name is optional, but to avoid name clash with other jars, package name should be unique. Use buildInfoPackage key for this.

buildInfoPackage := "hello"

build number

A build number can be generated as follows. Note that cross building against multiple Scala would each generate a new number.

buildInfoKeys += buildInfoBuildNumber

Eclipse support

If you use the sbteclipse plugin to generate projects for Eclipse, you need to tell sbteclipse that the generated BuildInfo.scala is a managed source, i.e., a generated source file.

To do so, you can configure sbteclipse as follows:

EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Managed

This is explained in more detail in the sbtecliipse documentation.


MIT License

Something went wrong with that request. Please try again.