如何在具有多个子项目的SBT项目中覆盖子项目中的设置

如何在具有多个子项目的SBT项目中覆盖子项目中的设置

问题描述:

我有一个项目,其中子项目添加为子目录中的git子模块,每个独立项目都有自己的 build.sbt 文件.根项目取决于并聚合这些子项目.如何在这些子项目中覆盖设置值(例如 organization version )?

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)

尝试将状态替代项放入

Try putting state overrides in onLoad which is

类型 State =>的

状态

,并在所有项目都执行后执行一次构建并加载.

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

例如,

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
}

避免递归 onLoad 执行#3544

settingsAlreadyOverriden is necessary for Avoiding recursive onLoad execution #3544

相关问题