I searched if this is possible for a while with little success.
Using SBT, can you create a subproject programmatically without pointing each project to its own val?
My current project structure looks something like this:
root/
common/ <--- This is another sub-project that others dependOn
project/
build.scala
src/main/scala
apps/ <--- sub-projects live here
Sub1/
Sub2/
Sub1and Sub2are their own SBT projects.
My first attempt to link these projects together looked like this:
import sbt._
import Keys._
object build extends Build {
lazy val common = project
val names = List("Sub1", "Sub2")
lazy val deps = names map { name =>
Project(id = name, base = file(s"apps/$name")).dependsOn(common)
}
lazy val finalDeps = common :: deps
lazy val root = project.in(file(".")).aggregate(finalDeps.map(sbt.Project.projectToRef) :_*)
.dependsOn(finalDeps.map(ClassPathDependency(_, None)) :_*)
}
However, since SBT uses reflection to create projects and subprojects, this does not work.
It only works if each subproject is explicitly specified:
lazy val Sub1 = project.in(file("apps/Sub1"))
So the question is:
Is there a way to programmatically build dependencies between projects in SBT?
source
share