{"id":13665247,"url":"https://github.com/sbt/sbt-buildinfo","last_synced_at":"2025-10-05T05:55:42.825Z","repository":{"id":2625753,"uuid":"3611276","full_name":"sbt/sbt-buildinfo","owner":"sbt","description":"I know this because build.sbt knows this.","archived":false,"fork":false,"pushed_at":"2025-03-13T14:05:44.000Z","size":424,"stargazers_count":556,"open_issues_count":12,"forks_count":91,"subscribers_count":22,"default_branch":"develop","last_synced_at":"2025-04-14T08:16:25.893Z","etag":null,"topics":["code-generator","sbt","sbt-plugin"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbt.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-03-03T14:47:30.000Z","updated_at":"2025-03-22T13:31:40.000Z","dependencies_parsed_at":"2023-02-17T21:01:09.819Z","dependency_job_id":"fd65202a-3755-464c-8d41-3e03f1bd0134","html_url":"https://github.com/sbt/sbt-buildinfo","commit_stats":{"total_commits":223,"total_committers":48,"mean_commits":4.645833333333333,"dds":0.5829596412556054,"last_synced_commit":"a31349509c0c79580742256d9512eafff2bd45d5"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-buildinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-buildinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-buildinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-buildinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbt","download_url":"https://codeload.github.com/sbt/sbt-buildinfo/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844000,"owners_count":21170499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generator","sbt","sbt-plugin"],"created_at":"2024-08-02T06:00:30.711Z","updated_at":"2025-10-05T05:55:42.761Z","avatar_url":"https://github.com/sbt.png","language":"Scala","funding_links":[],"categories":["Table of Contents","Sbt plugins","SOURCE"],"sub_categories":["Sbt plugins"],"readme":"sbt-buildinfo\n=============\n\n*I know this because build.sbt knows this.*\n\nsbt-buildinfo generates Scala source from your build definitions.\n\nLatest Stable\n-------------\n\nFor sbt 1.x add sbt-buildinfo as a dependency in `project/plugins.sbt`:\n\n[![sbt-buildinfo Scala version support](https://index.scala-lang.org/sbt/sbt-buildinfo/sbt-buildinfo/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/sbt/sbt-buildinfo/sbt-buildinfo)\n\n```scala\naddSbtPlugin(\"com.eed3si9n\" % \"sbt-buildinfo\" % \"x.y.z\")\n```\n\n- For `sbt \u003e= 0.13.6`, see [0.11.0](https://github.com/sbt/sbt-buildinfo/tree/v0.11.0).\n- For `sbt \u003c 0.13.6`, see [0.3.2](https://github.com/sbt/sbt-buildinfo/tree/0.3.2).\n\nUsage\n-----\n\nAdd the following in your `build.sbt`:\n\n```scala\nlazy val root = (project in file(\".\")).\n  enablePlugins(BuildInfoPlugin).\n  settings(\n    buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),\n    buildInfoPackage := \"hello\"\n  )\n```\n\nWhen you reload the settings and compile, this generates the following:\n\n```scala\npackage hello\n\n/** This object was generated by sbt-buildinfo. */\ncase object BuildInfo {\n  /** The value is \"helloworld\". */\n  val name: String = \"helloworld\"\n  /** The value is \"0.1-SNAPSHOT\". */\n  val version: String = \"0.1-SNAPSHOT\"\n  /** The value is \"2.10.3\". */\n  val scalaVersion: String = \"2.10.3\"\n  /** The value is \"0.13.2\". */\n  val sbtVersion: String = \"0.13.2\"\n  override val toString: String = \"name: %s, version: %s, scalaVersion: %s, sbtVersion: %s\".format(name, version, scalaVersion, sbtVersion)\n}\n```\n\nAs 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`\n\nCustomize `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:\n\n```scala\nbuildInfoKeys ++= Seq[BuildInfoKey](\n  resolvers,\n  Test / libraryDependencies,\n  BuildInfoKey.map(name) { case (k, v) =\u003e \"project\" + k.capitalize -\u003e v.capitalize },\n  \"custom\" -\u003e 1234, // computed at project load time\n  BuildInfoKey.action(\"buildTime\") {\n    System.currentTimeMillis\n  } // re-computed each time at compile\n)\n```\n\nThis generates:\n\n```scala\n  /** The value is Seq(\"Sonatype Public: https://oss.sonatype.org/content/groups/public\"). */\n  val resolvers: Seq[String] = Seq(\"Sonatype Public: https://oss.sonatype.org/content/groups/public\")\n  /** The value is Seq(\"org.scala-lang:scala-library:2.9.1\", ...). */\n  val test_libraryDependencies: Seq[String] = Seq(\"org.scala-lang:scala-library:2.9.1\", ...)\n  /** The value is \"Helloworld\". */\n  val projectName = \"Helloworld\"\n  /** The value is 1234. */\n  val custom = 1234\n  /** The value is 1346906092160L. */\n  val buildTime = 1346906092160L\n```\n\nTasks can be added only if they do not depend on `sourceGenerators`. Otherwise, it will cause an infinite loop.\n\nHere's how to change the generated object name:\n\n```scala\nbuildInfoObject := \"Info\"\n```\n\nThis 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.\n\n```scala\nbuildInfoPackage := \"hello\"\n```\n\n### build number\n\nA build number can be generated as follows. Note that cross building against multiple Scala would each generate a new number.\n\n```scala\nbuildInfoKeys += buildInfoBuildNumber\n```\n\n### BuildInfoOption.ToMap\n\nAdd the following option\n\n```scala\nbuildInfoOptions += BuildInfoOption.ToMap\n```\n\nto generate `toMap` method:\n\n```scala\nval toMap = Map[String, Any](\n  \"name\" -\u003e name,\n  \"version\" -\u003e version,\n  \"scalaVersion\" -\u003e scalaVersion,\n  \"sbtVersion\" -\u003e sbtVersion)\n```\n\n### BuildInfoOption.ToJson\n\nAdd the following option\n\n```scala\nbuildInfoOptions += BuildInfoOption.ToJson\n```\n\nto generate `toJson` method.\n\n### BuildInfoOption.Traits\n\nAdd the following option\n\n```scala\nbuildInfoOptions += BuildInfoOption.Traits(\"TestTrait1\", \"TestTrait2\")\n```\n\nto mixin traits to the generated object.\n\n### BuildInfoOption.BuildTime\n\nAdd the following option\n\n```scala\nbuildInfoOptions += BuildInfoOption.BuildTime\n```\n\nto add timestamp values:\n\n```scala\n/** The value is \"2015-07-30 03:30:16.849-0700\". */\nval builtAtString: String = \"2015-07-30 03:30:16.849-0700\"\n/** The value is 1438227016849L. */\nval builtAtMillis: Long = 1438227016849L\n```\n\n### BuildInfoOption.PackagePrivate\n\nSet the package using `buildInfoPackage` and use the option `BuildInfoOption.PackagePrivate`\n\n```scala\nbuildInfoPackage := \"hello\"\nbuildInfoOptions += BuildInfoOption.PackagePrivate\n```\n\nto make the generated `BuildInfo` object package private:\n\n```scala\n/** This object was generated by sbt-buildinfo. */\nprivate[hello] case object BuildInfo {  \n  ...\n}\n```\n\n### BuildInfoOption.ConstantValue\n\nAdd the following option\n\n```scala\nbuildInfoOptions += BuildInfoOption.ConstantValue\n```\nto have all vals in the `BuildInfo` object declared `final` and without an explicit type annotation:\n\n```scala\n/** This object was generated by sbt-buildinfo. */\ncase object BuildInfo {\n  /** The value is \"helloworld\". */\n  final val name = \"helloworld\"\n  ...\n}\n```\n\nThis is particular useful if the values must be constants \u0026ndash; e.g., if you need to assign them to annotation arguments.\n\n### BuildInfoOption.ImportScalaPredef\n\nAdd the following option\n\n```scala\nbuildInfoOptions += BuildInfoOption.ImportScalaPredef\n```\n\nto explicitly import `scala.Predef._` in the generated code.\n\n```scala\npackage hello\n\nimport scala.Predef._\n\n/** This object was generated by sbt-buildinfo. */\ncase object BuildInfo {\n  ...\n}\n```\n\nThis 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 `*`.\n\nLicense\n-------\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbt%2Fsbt-buildinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbt%2Fsbt-buildinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbt%2Fsbt-buildinfo/lists"}