• Stars
    star
    550
  • Rank 80,805 (Top 2 %)
  • Language
    Scala
  • License
    MIT License
  • Created over 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

I know this because build.sbt knows this.

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:

sbt-buildinfo Scala version support

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "x.y.z")
  • For sbt >= 0.13.6, see 0.11.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

/** 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 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

BuildInfoOption.PackagePrivate

Set the package using buildInfoPackage and use the option BuildInfoOption.PackagePrivate

buildInfoPackage := "hello"
buildInfoOptions += BuildInfoOption.PackagePrivate

to make the generated BuildInfo object package private:

/** This object was generated by sbt-buildinfo. */
private[hello] case object BuildInfo {  
  ...
}

BuildInfoOption.ConstantValue

Add the following option

buildInfoOptions += BuildInfoOption.ConstantValue

to have all vals in the BuildInfo object declared final and without an explicit type annotation:

/** This object was generated by sbt-buildinfo. */
case object BuildInfo {
  /** The value is "helloworld". */
  final val name = "helloworld"
  ...
}

This is particular useful if the values must be constants – e.g., if you need to assign them to annotation arguments.

BuildInfoOption.ImportScalaPredef

Add the following option

buildInfoOptions += BuildInfoOption.ImportScalaPredef

to explicitly import scala.Predef._ in the generated code.

package hello

import scala.Predef._

/** This object was generated by sbt-buildinfo. */
case object BuildInfo {
  ...
}

This import is necessary only when using compiler option -Yno-imports. Please note, the generated import is not compatible when compiling with Scala 3 compiler option -source:future because import wildcards must be *.

License

MIT License

More Repositories

1

sbt

sbt, the interactive build tool
Scala
4,685
star
2

sbt-native-packager

sbt Native Packager
Scala
1,594
star
3

sbt-dependency-graph

sbt plugin to create a dependency graph for your project
Scala
1,245
star
4

sbt-jmh

"Trust no one, bench everything." - sbt plugin for JMH (Java Microbenchmark Harness)
Scala
789
star
5

sbt-eclipse

Plugin for sbt to create Eclipse project definitions
Scala
716
star
6

sbt-release

A release plugin for sbt
Scala
642
star
7

sbt-web

Library for building sbt plugins for the web
Scala
368
star
8

sbt-git

A git plugin for sbt
Scala
342
star
9

zinc

Scala incremental compiler library, used by sbt and other build tools
Scala
333
star
10

docker-sbt

Official sbt docker images
Dockerfile
317
star
11

sbt-dynver

An sbt plugin to dynamically set your version from git
Scala
299
star
12

sbt-ci-release

sbt plugin to automate Sonatype releases from GitHub Actions
Scala
283
star
13

sbt-onejar

Packages your project using One-JARâ„¢
Scala
267
star
14

sbt-scalariform

sbt plugin adding support for source code formatting using Scalariform
Scala
258
star
15

sbt-fresh

sbt-plugin to create an opinionated fresh sbt project
Scala
233
star
16

sbt-github-actions

An sbt plugin which makes it easier to build with GitHub Actions
Scala
195
star
17

sbt-header

sbt-header is an sbt plugin for creating file headers, e.g. copyright headers
Scala
186
star
18

sbt-bintray

fresh packages delivered from your sbt console
Scala
179
star
19

sbt-protobuf

sbt plugin for compiling protobuf files
Scala
173
star
20

sbt-site

Site generation for sbt
Scala
173
star
21

sbt-start-script

SBT Plugin to create a "start" script to run the program
Scala
144
star
22

sbt-pgp

PGP plugin for sbt
Scala
142
star
23

sbt-groll

sbt plugin to roll the Git history
Scala
133
star
24

junit-interface

Implementation of sbt's test interface for JUnit
Java
132
star
25

sbt-jni

SBT Plugin to ease working with JNI
Scala
125
star
26

sbt-unidoc

sbt plugin to create a unified Scaladoc or Javadoc API document across multiple subprojects.
Scala
124
star
27

sbt-jacoco

an sbt plugin for JaCoCo Code Coverage
Scala
123
star
28

sbt-projectmatrix

Scala
119
star
29

sbt-boilerplate

sbt plugin for generating scala.Tuple/Function related boilerplate code
Scala
109
star
30

sbt-proguard

Proguard sbt plugin
Scala
99
star
31

sbt-atmos

sbt plugin for running Typesafe Console in development
Scala
98
star
32

sbt-dirty-money

clean Ivy2 cache
Scala
89
star
33

sbt-launcher-package

Packaging for sbt so you can run it.
Scala
89
star
34

sbt-license-report

Report on licenses used in an sbt project.
Scala
85
star
35

website

The source for scala-sbt.org
Scala
77
star
36

sbt-doge

sbt plugin to aggregate tasks across subprojects and their crossScalaVersions
Scala
77
star
37

sbt-pom-reader

Translates xml -> awesome. Maven-ish support for sbt.
Scala
76
star
38

sbt-remote-control

Create and manage sbt process using unicorns and forks
Scala
74
star
39

sbt-aspectj

AspectJ sbt plugin
Scala
72
star
40

sbt-scalabuff

SBT plugin which generate case classes and support for serialization from Google Protocol Buffer definitions using ScalaBuff
Scala
72
star
41

contraband

http://www.scala-sbt.org/contraband/
Scala
67
star
42

sbt-s3

sbt-s3 is a simple sbt plugin to manipulate objects on Amazon S3
Scala
63
star
43

sbt-javaagent

sbt plugin for adding java agents to projects
Scala
56
star
44

sbt-multi-jvm

Multi-JVM testing in sbt
Scala
56
star
45

sbt-paradox-material-theme

Material Design theme for Paradox
StringTemplate
53
star
46

sbt-cpd

Copy & Paste Detector plugin using PMD for sbt.
Scala
48
star
47

sbt-osgi

sbt plugin for creating OSGi bundles
Scala
47
star
48

sbt-man

Looks up scaladoc.
Scala
46
star
49

sbt-findbugs

FindBugs static analysis plugin for sbt.
Scala
46
star
50

librarymanagement

librarymanagement module for sbt
Scala
46
star
51

ipcsocket

IPC: Unix Domain Socket and Windows Named Pipes for Java
Java
45
star
52

sbt-less

Scala
42
star
53

io

IO module for sbt
Scala
40
star
54

sbt-js-engine

Support for sbt plugins that use JavaScript
Scala
40
star
55

launcher

The sbt launcher as its own project. Can launch any ivy/maven published project with a main class, with some fancy features.
Scala
40
star
56

sbt-autoversion

Scala
37
star
57

sbt-avro

sbt plugin for compiling Avro schemas, similar to sbt-protobuf
Scala
33
star
58

sbt-jupiter-interface

Implementation of sbt's test interface for JUnit 5's Jupiter module
Java
32
star
59

sbt-digest

sbt-web plugin for checksum files
Scala
32
star
60

sbt-slash

unified slash syntax for both shell and build.sbt
Scala
29
star
61

sbt-java-formatter

An sbt plugin for formating Java code
Scala
28
star
62

sbt-gzip

sbt-web plugin for gzipping assets
Scala
26
star
63

sbt-pull-request-validator

Plugin that optimizes pull request validation to only validate sub projects that have changed
Scala
24
star
64

sbt-unique-version

emulates Maven's uniqueVersion snapshots
Scala
24
star
65

sbt-duplicates-finder

Find classes and resources conflicts in your build
Scala
22
star
66

sbt.github.com

See https://github.com/sbt/website for the source
HTML
22
star
67

sbt-autoplugin.g8

giter8 template for sbt 0.13.5+ AutoPlugin
Scala
20
star
68

sbt-cucumber

Cucumber plugin for SBT.
Scala
20
star
69

sbt-jcstress

Trust no-one, and especially not memory visibility.
HTML
19
star
70

adept

adept helps you find, declare, and download dependencies. http://groups.google.com/group/adept-dev/
18
star
71

sbt-sriracha

Scala
17
star
72

sbt-mocha

SBT plugin for running mocha JavaScript unit tests on node
Scala
17
star
73

sbt-multi-release-jar

Support for JDK9's Multi Release JAR Files (JEP 238)
Scala
17
star
74

sbt-xjc

SBT plugin to compile an XML Schema with XJC
Scala
15
star
75

util

util modules for sbt
Scala
15
star
76

sbt-export-repo

exports your dependency graph to a preloaded local repository
Scala
15
star
77

sbt-nocomma

sbt-nocomma reduces commas from your build.sbt.
Scala
13
star
78

serialization

serialization facility for sbt
Scala
13
star
79

sbt-maven-resolver

An sbt plugin to resolve dependencies using Aether
Scala
12
star
80

sbt-core-next

sbt APIs targeted for eventual inclusion in sbt core
Scala
12
star
81

sbt-houserules

House rules for sbt modules.
Scala
12
star
82

sbt-pamflet

sbt plugin to run Pamflet (and Pamflet plugin to run sbt)
Scala
11
star
83

sbt-sdlc

Scaladoc link checker for sbt
Scala
11
star
84

sbt-appbundle

A plugin for the simple-build-tool to create an OS X application bundle.
Scala
10
star
85

bintry

your packages, delivered fresh
Scala
10
star
86

sbt-fmpp

FreeMarker Scala/Java Templating Plugin for SBT
Scala
9
star
87

sbt-ynolub

Scala
9
star
88

sbt-testng

Implementation of the sbt testing interface for TestNG, bundled with an sbt plug-in for convenience.
Scala
9
star
89

sbt-concat

sbt-web plugin for concatenating web assets
Scala
8
star
90

sbt-ant

SBT plug-in to call Ant targets from within SBT builds
Scala
7
star
91

sbtn-dist

Shell
6
star
92

sbt-community-plugins

All community plugins that opt into an uber-build
Scala
6
star
93

sbt-vimquit

an sbt plugin that adds :q command.
Scala
5
star
94

helloworld-one

An example build for sbt 1.0.0.
Scala
5
star
95

sbt-giter8-resolver

Scala
5
star
96

sbt-sequential

adds sequential tasks to sbt
Scala
4
star
97

sbt-scalashim

generates sys.error.
Scala
4
star
98

sbt-experimental

Experimental APIs to fix rough edges in sbt
Scala
3
star
99

sbt-web-build-base

Scala
3
star
100

sbt-validator

Builds sbt 1.0.x against recent versions of the sbt modules
Shell
3
star