ɹɐʎɯɐʞ
ɹɐʎɯɐʞ

Reputation: 568

How can I override settings in subprojects in an SBT project with multiple subprojects

I have a project with with subprojects added as git submodules in subdirectories, each independent projects having their own build.sbt files. The root projects depends on and aggregates these subprojects. How can I override a setting value (e.g. organization or version) inside those subprojects?

lazy val p1 = (project in file("p1"))
  .settings(organization := "xyz.abc") // This does not work :(

lazy val root = (project in file("."))
  .dependsOn(p1)
  .aggregate(p1)

Upvotes: 3

Views: 433

Answers (1)

Mario Galic
Mario Galic

Reputation: 48430

Try putting state overrides in onLoad which is

of type State => State and is executed once, after all projects are built and loaded.

For example,

lazy val settingsAlreadyOverriden = SettingKey[Boolean]("settingsAlreadyOverriden","Has overrideSettings command already run?")
settingsAlreadyOverriden := false
commands += Command.command("overrideSettings") { state =>
  if (settingsAlreadyOverriden.value) {
    state
  } else {
    Project.extract(state).appendWithSession(
      Seq(
        settingsAlreadyOverriden := true,
        subprojectA / organization := "kerfuffle.org",
      ),
      state
    )
  }
}

onLoad in Global := {
  ((s: State) => { "overrideSettings" :: s }) compose (onLoad in Global).value
}

settingsAlreadyOverriden is necessary for Avoiding recursive onLoad execution #3544

Related questions

Upvotes: 2

Related Questions