Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT common build settings

Tags:

scala

sbt

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
}
like image 307
Dzhu Avatar asked Oct 02 '12 07:10

Dzhu


1 Answers

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:

  • Resolver configuration
  • Simplified dependency resolution with automatic updating
  • Clarity on what transitive dependencies are used
  • Optional protection from snapshot versions
  • Cleaned-up logging configuration

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.

like image 106
David Soergel Avatar answered Nov 17 '22 04:11

David Soergel