lightbend-labs / dbuild

Multi-project build tool, based on sbt.
https://lightbend-labs.github.io/dbuild
Other
83 stars 14 forks source link

Add ability to modify settings on all sbt subprojects in a given project #144

Closed gkossakowski closed 1 year ago

gkossakowski commented 9 years ago

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

SethTisue commented 8 years ago

I also ended up adding removeScalacOptions in https://github.com/scala/community-builds/commit/18dbba80b4e24f5a3fb95239b274d5a8bf78012c

SethTisue commented 1 year ago

addScalacOptions and removeScalacOptions are the only things the community build has ever really needed in this space