You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
When you reload the settings and compile, this generates the following:
packagehello/** This object was generated by sbt-buildinfo.*/caseobjectBuildInfo {/** The value is "helloworld".*/valname:String="helloworld"/** The value is "0.1-SNAPSHOT".*/valversion:String="0.1-SNAPSHOT"/** The value is "2.10.3".*/valscalaVersion:String="2.10.3"/** The value is "0.13.2".*/valsbtVersion:String="0.13.2"overridevaltoString:String="name: %s, version: %s, scalaVersion: %s, sbtVersion: %s".format(name, version, scalaVersion, sbtVersion)}
As this is generated source it will be found undertarget, specifically for a Scala 2.11 project undertarget/scala-2.11/src_managed/main/sbt-buildinfo
CustomizebuildInfoKeys by adding whatever keys you want to have inBuildInfo. You can useBuildInfoKey.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 bothSettingKey[T] andTaskKey[T] types as arguments:
buildInfoKeys++=Seq[BuildInfoKey]( resolvers,Test/ libraryDependencies,BuildInfoKey.map(name) {case (k, v)=>"project"+ k.capitalize-> v.capitalize },"custom"->1234,// computed at project load timeBuildInfoKey.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").*/valresolvers:Seq[String]=Seq("Sonatype Public: https://oss.sonatype.org/content/groups/public")/** The value is Seq("org.scala-lang:scala-library:2.9.1", ...).*/valtest_libraryDependencies:Seq[String]=Seq("org.scala-lang:scala-library:2.9.1", ...)/** The value is "Helloworld".*/valprojectName="Helloworld"/** The value is 1234.*/valcustom=1234/** The value is 1346906092160L.*/valbuildTime=1346906092160L
Tasks can be added only if they do not depend onsourceGenerators. Otherwise, it will cause an infinite loop.
Here's how to change the generated object name:
buildInfoObject:="Info"
This changes the generated object name toobject Info. Changing the object name is optional, but to avoid name clash with other jars, package name should be unique. UsebuildInfoPackage 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.
/** The value is "2015-07-30 03:30:16.849-0700".*/valbuiltAtString:String="2015-07-30 03:30:16.849-0700"/** The value is 1438227016849L.*/valbuiltAtMillis:Long=1438227016849L
BuildInfoOption.PackagePrivate
Set the package usingbuildInfoPackage and use the optionBuildInfoOption.PackagePrivate
to explicitly importscala.Predef._ in the generated code.
packagehelloimportscala.Predef._/** This object was generated by sbt-buildinfo.*/caseobjectBuildInfo { ...}
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*.