Setting up multi-projects with SBT

25 Mar 2017

Setting up multi-projects in SBT requires 2 wisdoms:

  1. We might need both aggregate and dependsOn. aggregate means that a task (e.g. compile) is performed in the main project as well as the subproject, while dependsOn adds the subproject's class path to the main project.
  2. IntelliJ can't detect a subproject that is not a subfolder of the main project's folder. I was stuck with this for a while.

Here's the main project's build.sbt:

lazy val root = (project in file(".")) .dependsOn(model) .aggregate(model) lazy val model = ProjectRef(file("model"), "model")

The subproject's build.sbt looks like this:

lazy val model = (project in file(".")) .settings(name := "model")

That's it. It works!

Give it a kudos