2
votes

If I have a project/Build.scala:

object MyBuild extends Build {
  ...
  override val settings = super.settings ++ Seq(
    foo := "blah",
    bar := 5
  )
}

Is that settings field scoped to ThisBuild? Global? Consider especially a multi-project build. If there's a root aggregate project, how do those settings flow to subprojects?

To elaborate, in this page it says, "settings in .sbt files are appended to the settings in .scala files." What I want to know is what "appended settings" correspond to in scope-land, since I saw on twitter that .scala builds are on their way out and I want to migrate my build to .sbt configurations.

1

1 Answers

3
votes

.scala build definition you also linked says:

In .scala files, you can add settings to Build.settings for sbt to find, and they are automatically build-scoped.

project/build.scala

We can test this:

import sbt._, Keys._

object MyBuild extends Build {
  val foo = settingKey[String]("foo")

  override val settings = super.settings ++ Seq(
    foo := "foo"
  )
}

From the shell run:

> inspect foo

You should get something like

> inspect foo
[info] Setting: java.lang.String = foo
[info] Description:
[info]  foo
[info] Provided by:
[info]  {file:/Users/x/workspace/helloapp/}/*:foo
[info] Defined at:
[info]  /Users/x/workspace/helloapp/project/build.scala:7
[info] Delegates:
[info]  *:foo
[info]  {.}/*:foo
[info]  */*:foo
[info] Related:
[info]  {.}/*:foo

The key here is "provided by", which is {file:/Users/x/workspace/helloapp/}/*:foo. See Scopes on the details on how to decipher that notation, but it means it's scoped to the entire build of helloapp.