Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT multi-project build without using lazy vals

Tags:

scala

sbt

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?

like image 626
Rui Gonçalves Avatar asked Mar 20 '17 11:03

Rui Gonçalves


Video Answer


1 Answers

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)
...
like image 197
OlivierBlanvillain Avatar answered Sep 27 '22 20:09

OlivierBlanvillain