dbuild
dbuild copied to clipboard
Add ability to modify settings on all sbt subprojects in a given project
Dbuild lets you modify settings only in a specific scope. Modifying the setting in all subprojects requires specifying it for each subproject individually. We would need a mechanism similar to set every
, instead.
Possible workaround
You can introduce a custom command called appendScalacOptions
and use it when needed.
commands += "set commands += {\n def appendScalacOptions(s: State, args: Seq[String]): State = {\n val extracted = Project extract s\n def appendDistinct[A](x: Seq[A], y: Seq[A]) = x.filterNot(y.contains) ++ y\n import extracted._\n val r = Project.relation(extracted.structure, true)\n val allDefs = r._1s.toSeq\n val projectScope = Load.projectScope(currentRef)\n val scopes = allDefs.filter(_.key == scalacOptions.key).map(_.scope).distinct\n val redefined = scopes.map(scope => scalacOptions in scope <<= (scalacOptions in scope).map(orig => appendDistinct(orig, args)))\n val session = extracted.session.appendRaw(redefined)\n BuiltinCommands.reapply(session, structure, s) \n }\n Command.args(\"appendScalacOptions\", \"<option>\")(appendScalacOptions)\n}"
The snippet has been taken from: https://github.com/scala/community-builds/blob/7d8bcd05fb6108fde975abc3d176e2fe06aeb458/common-2.11.x.conf#L136
I also ended up adding removeScalacOptions
in https://github.com/scala/community-builds/commit/18dbba80b4e24f5a3fb95239b274d5a8bf78012c
addScalacOptions
and removeScalacOptions
are the only things the community build has ever really needed in this space