I have multiple SBT projects that all have a common setup - e.g. multi module, publishTo settings etc etc.
How do I provide a common e.g. CommonBuild class that each of the projects can extend from it? For example:
trait CommonBuild {
val publishSettings = Seq(
publishTo := Some("", ""),
credentials += ...
)
def module(name: String) (
settings: Seq[Setting[_]],
projectId: String = PROJECT + "-" + name,
dirName: String = name,
srcPath: String = PROJECT + name
) = Project(projectId, file(dirName), settings = (buildSettings ++ srcPathSetting(projectId, srcPath)) ++ publishSettings ++ settings)
}
Now it can be used by a project build:
object ProjABuild extends CommonBuild {
// use CommonBuild methods / vals
}
object ProjBBuild extends CommonBuild {
// use CommonBuild methods / vals
}
I wanted to do this too. Importantly, the common setup needs to live in its own project on which the subprojects depend, so that a change made to the common setup automatically takes effect in all of the subprojects. The only way to accomplish this is to put the common stuff in an SBT plugin.
I wrote such a plugin, called iesl-sbt-base. It provides a pile of boilerplate, so that the Build.scala file for your project can be trivially short. It provides:
Please see https://github.com/iesl/iesl-sbt-base for details. You'll probably want to fork that to change things that are specific to my setup (e.g., especially resolver URLs). If there's demand, I can think about how to make it more configurable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With