ThisBuild ignored for plugin settingKey

85 views Asked by At

This issue is connected with my troubles with sbt-scapegoat but I would like to understand this thing globally.

So, sbt-scapegoat defines a setting scapegoatVersion and config scapegoat. Short and complete source code is availible here.

When I set scapegoatVersion in ThisBuild := "1.3.0" it is ignored:

> scapegoat:scapegoatVersion
[info] frontend/scapegoat:scapegoatVersion
[info]  1.0.0
[info] backend/scapegoat:scapegoatVersion
[info]  1.0.0
[info] {.}/scapegoat:scapegoatVersion
[info]  1.3.0

I understand it is so, because scapegoatVersion := "1.0.0" is imported for every project from autoImport object, and such setting is more precise than scapegoatVersion in ThisBuild so overrides it.

My question is: how such default value should be defined in a plugin to allow global overrides with ThisBuild or Global.

@edit: I've found that version setting i Defaults.scala is defined using :== instead of :=. Is this a trick I'm looking for? Sadly it's not documented and moreover, it's private to sbt package.

1

There are 1 answers

2
Stefano Bonetti On

I think by applying the scapegoatVersion to ThisBuild you are setting it only for the "parent project" (also identified as {.}).

From the logs you pasted it looks like you got 2 submodules, for which the default scapegoatVersion still applies.

Have you tried defining the version in some commonSettings variable and apply it to the submodules? Something along the lines of:

lazy val commonSettings = Seq(
  scapegoatVersion := "1.3.0"
)

lazy val backend = (project in file("backend"))
  .settings(commonSettings: _*)
  ...

lazy val frontend = (project in file("frontend"))
  .settings(commonSettings: _*)
  ...