sbt / sbt-buildinfo

I know this because build.sbt knows this.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Also support the test configuration

gzm0 opened this issue · comments

We are starting to use sbt-buildinfo in Scala.js core (scala-js/scala-js#4660) to replace a hand-built version of it.

However, we mostly need this in the test configuration. We can currently achieve this by:

  • No enabling BuildInfoPlugin
  • Adding BuildInfoPlugin.buildInfoDefaultSettings, BuildInfoPlugin.buildInfoScopedSettings(Test) to the relevant project's setting.

Should we add an "official" way of doing this?

Sure. I'd be happy to review a PR if you are up for sending one :)

I've needed this before too. My workaround has been to create a new, no-publish sub-project to enable BuildInfo and depend on it in the test scope of my other sub-projects. Example:
https://github.com/typelevel/bobcats/blob/48f65d5efbf0f8ecb49d4d9eda25e9f964d9735d/build.sbt#L105-L107

IMHO the main challenge is the interface: Currently, BuildInfo generates relevant code by merely being enabled. However, since enabling a plugin is a per project setting and not a per configuration setting, this will not generalize.

A good interface would be to drop the default value of buildinfoKeys and make generation dependent on that key being non-empty.

However, this comes with major compatibility issues for existing builds:

  • Builds relying bn the default value will fail to compile (object missing).
  • Builds setting buildInfoKeys (without configuration scope) will fail to compile in the test configuration because the object will be duplicate.

Similar arguments apply to other keys (package, object name).

An alternative would be to introduce buildinfoEnable and set it to true in the compile config and false in the test config. However, the need to "double enable" really bothers me.