All Projects → sbt → Sbt Buildinfo

sbt / Sbt Buildinfo

Licence: mit
I know this because build.sbt knows this.

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Sbt Buildinfo

sbt-flaky
Detect flaky tests with sbt
Stars: ✭ 35 (-92.8%)
Mutual labels:  sbt, sbt-plugin
sbt-ammonite-classpath
Export the classpath for Ammonite and Almond
Stars: ✭ 29 (-94.03%)
Mutual labels:  sbt, sbt-plugin
sbt-example
Run Scaladoc as unit tests
Stars: ✭ 30 (-93.83%)
Mutual labels:  sbt, sbt-plugin
sbt-bazel
Easily convert SBT projects to Bazel workspaces
Stars: ✭ 55 (-88.68%)
Mutual labels:  sbt, sbt-plugin
Xsbt Web Plugin
Servlet support for sbt
Stars: ✭ 381 (-21.6%)
Mutual labels:  sbt, sbt-plugin
xsbt-webstart
A Webstart plugin for sbt
Stars: ✭ 12 (-97.53%)
Mutual labels:  sbt, sbt-plugin
sbt-elm
Scala Build Tool (SBT) plugin for the Elm programming language
Stars: ✭ 44 (-90.95%)
Mutual labels:  sbt, sbt-plugin
sbt-swagger-2
sbt plugin for generating Swagger JSON schemas during build
Stars: ✭ 13 (-97.33%)
Mutual labels:  sbt, sbt-plugin
sbt-hepek
Sbt plugin for rendering Scala objects to files. And more!
Stars: ✭ 17 (-96.5%)
Mutual labels:  sbt, sbt-plugin
sbt-jni
SBT Plugin to ease working with JNI
Stars: ✭ 110 (-77.37%)
Mutual labels:  sbt, sbt-plugin
sbt-project-switcher
A sbt plugin to switch project in a snappy way⚡️
Stars: ✭ 36 (-92.59%)
Mutual labels:  sbt, sbt-plugin
sbt-assembly
Deploy über-JARs. Restart processes. (port of codahale/assembly-sbt)
Stars: ✭ 1,801 (+270.58%)
Mutual labels:  sbt, sbt-plugin
sbt-travisci
An sbt plugin to integrate with Travis CI
Stars: ✭ 44 (-90.95%)
Mutual labels:  sbt, sbt-plugin
chuckwagon
a Scala/sbt AWS Lambda Toolkit
Stars: ✭ 29 (-94.03%)
Mutual labels:  sbt, sbt-plugin
sbt-rewarn
Make sbt always display compilation warnings, even for unchanged files.
Stars: ✭ 42 (-91.36%)
Mutual labels:  sbt, sbt-plugin
sbt-kubeyml
Sbt plugin to help deploy Scala applications to Kubernetes
Stars: ✭ 37 (-92.39%)
Mutual labels:  sbt, sbt-plugin
sbt-findbugs
FindBugs static analysis plugin for sbt.
Stars: ✭ 47 (-90.33%)
Mutual labels:  sbt, sbt-plugin
gatling-sbt-plugin
Gatling Plugin for SBT
Stars: ✭ 105 (-78.4%)
Mutual labels:  sbt, sbt-plugin
sbt-ecr
An SBT plugin for managing Docker images within Amazon ECR.
Stars: ✭ 52 (-89.3%)
Mutual labels:  sbt, sbt-plugin
sbt-publish-more
📤 Publish artifacts to more than one repository
Stars: ✭ 21 (-95.68%)
Mutual labels:  sbt, sbt-plugin

sbt-buildinfo

I know this because build.sbt knows this.

sbt-buildinfo generates Scala source from your build definitions.

Latest Stable

For sbt 1.x add sbt-buildinfo as a dependency in project/plugins.sbt:

Bintray version

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "x.y.z")
  • For sbt >= 0.13.6, see 0.9.0.
  • For sbt < 0.13.6, see 0.3.2.

Usage

Add the following in your build.sbt:

lazy val root = (project in file(".")).
  enablePlugins(BuildInfoPlugin).
  settings(
    buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
    buildInfoPackage := "hello"
  )

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

package hello

import java.io.File
import java.lang._
import java.net.URL
import scala._; import Predef._

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

As this is generated source it will be found under target, specifically for a Scala 2.11 project under target/scala-2.11/src_managed/main/sbt-buildinfo

Customize buildInfoKeys by adding whatever keys you want to have in BuildInfo. You can use BuildInfoKey.map to change the generated field name and value, add new fields with tuples, or add new fields with values computed at build-time. Note: BuildInfoKey.map can can handle both SettingKey[T] and TaskKey[T] types as arguments:

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

This generates:

  /** The value is Seq("Sonatype Public: https://oss.sonatype.org/content/groups/public"). */
  val resolvers: Seq[String] = Seq("Sonatype Public: https://oss.sonatype.org/content/groups/public")
  /** The value is Seq("org.scala-lang:scala-library:2.9.1", ...). */
  val test_libraryDependencies: Seq[String] = 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

BuildInfoOption.ToMap

Add the following option

buildInfoOptions += BuildInfoOption.ToMap

to generate toMap method:

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

BuildInfoOption.ToJson

Add the following option

buildInfoOptions += BuildInfoOption.ToJson

to generate toJson method.

BuildInfoOption.Traits

Add the following option

buildInfoOptions += BuildInfoOption.Traits("TestTrait1", "TestTrait2")

to mixin traits to the generated object.

BuildInfoOption.BuildTime

Add the following option

buildInfoOptions += BuildInfoOption.BuildTime

to add timestamp values:

/** The value is "2015-07-30 03:30:16.849-0700". */
val builtAtString: String = "2015-07-30 03:30:16.849-0700"
/** The value is 1438227016849L. */
val builtAtMillis: Long = 1438227016849L

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].