Rui Gonçalves
Rui Gonçalves

Reputation: 1375

SBT multi-project build without using lazy vals

I'm working with a huge project with lots of subprojects, some of them with subprojects of their own. On top of that, I'd like some of them to be dynamic - given a List somewhere in the project build, I'd like to create one project for each of the elements.

For those reasons, having to define a lazy val for each project in build.sbt is very cumbersome. Is there other way to declare projects, like a addProject-like method we could call anywhere? Is there some SBT plugin that helps with that?

Upvotes: 8

Views: 192

Answers (1)

OlivierBlanvillain
OlivierBlanvillain

Reputation: 7768

Sbt uses macros to turns top level vals into projects, so I don't think you will be able to escape that part. However, you can define all you build in Project => Project functions: (note that you also composability "for free" with function composition)

def myConf: Project => Project =
  _.enablePlugins(ScalaJSPlugin)
   .settings(scalaVersion := "2.12.0")

Then simply use project.configure(myConf) for single line project definitions:

lazy val subProject1 = project.configure(myConf)
lazy val subProject2 = project.configure(myConf)
lazy val subProject3 = project.configure(myConf)
lazy val subProject4 = project.configure(myConf)
...

Upvotes: 1

Related Questions