The answer at https://stackoverflow.com/a/21605652/1737727 shows how to override one setting for a subproject defined with RootProject
from the main project. I was wondering if there is a nice way to do this for multiple settings, and then possibly for multiple subprojects, too, so you don't have to list every combination separately. This would be to prevent proliferation and reduce the chance of forgetting a combination and accidentally having a mismatch of settings.
When not using RootProject
, the SBT docs show how to do this with a common sequence of settings:
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0",
scalaVersion := "2.11.8"
)
lazy val core = (project in file("core")).
settings(commonSettings: _*).
settings(
// other settings
)
lazy val util = (project in file("util")).
settings(commonSettings: _*).
settings(
// other settings
)
But a RootProject
has no method to set its settings. I tried something like the following, according to the answer mentioned above:
lazy val util = RootProject(file("../util"))
commonSettings.map(_.key).foreach(key => key in util := key.value)
but this doesn't seem to be the right approach.
I have looked into using Global
or ThisBuild
scope, but each subproject sets the settings in its own build.sbt
file, which takes precedence over these wider scopes if I understand correctly.
Is there a nice way to do this, or should I just set each setting for each subproject manually? Should I use different scopes, e.g. the subprojects define their settings in Global
and the main project in ThisBuild
?