I would like to invent a system to dynamically discover subprojects and aggregate them into my project automatically. Or at least configure this somehow.
Here:
project/Build.scala
import sbt._
import sbt.Keys._
import play.sbt._
import play.sbt.Play.autoImport._
object Build extends Build {
val commonSettings: Seq[Setting[_]] = Seq(
scalaVersion := "2.11.7"
)
lazy val modules = (file("modules") * DirectoryFilter).get.map { dir =>
Project(dir.getName, dir).enablePlugins(PlayJava).settings(commonSettings: _*)
}
lazy val root = (project in file("."))
.enablePlugins(PlayJava)
.settings(
name := "mysite",
version := "1.0"
)
.settings(commonSettings: _*)
.dependsOn(modules map (m => m: ClasspathDependency): _*)
.aggregate(modules map (m => m: ProjectReference): _*)
override lazy val projects = root +: modules
}
Note, make sure that the module directories don't also contain build.sbt
files defining them as projects as that will cause confusing RuntimeException: No project 'x' in 'file:/x'
type exception, see Can't use sbt 0.13.7 with Play subprojects
You can try something like this:
import sbt._
import sbt.Keys._
import play.sbt._
import play.sbt.Play.autoImport._
object Build extends Build {
lazy val modules = (file("modules") * DirectoryFilter).get.map { dir =>
Project(dir.getName, dir).enablePlugins(PlayJava)
}
lazy val root = (project in file("."))
.enablePlugins(PlayJava)
.settings(
name := "mysite",
version := "1.0"
)
.dependsOn(modules map (m => m: ClasspathDependency): _*)
.aggregate(modules map (m => m: ProjectReference): _*)
override lazy val projects = root +: modules
}
Note: Inspired by Dale's answer, but I had to remove the "commonSettings", otherwise it would not work for me.