You can declare a source dependency from Foo to Bar via a project reference:
import sbt._
object FooBuild extends Build {
lazy val root = Project(
id = "foo",
base = file(".")
) dependsOn(theBarBuild)
lazy val theBarBuild = ProjectRef(
base = file("/path/to/bar"),
id = "bar")
}
This should also recompile Bar (if it has changed) whenever you compile Foo. Please note that the id
of the project reference must match the actual id of the Bar project, which might be something like e.g. default-edd2f8
if you use a simple build definition (.sbt
files only).
This technique is especially useful for plug-ins (see my blog post about this topic).
Edit:
You can kind of re-code the checkout behaviour like this:
import sbt._
object FooBuild extends Build {
lazy val root = addCheckouts(Project(id = "foo", base = file(".")))
def addCheckouts(proj: Project): Project = {
val checkouts = proj.base.getCanonicalFile / "checkouts"
if (! checkouts.exists) proj
else proj.dependsOn(IO.listFiles(DirectoryFilter)(checkouts).map { dir =>
ProjectRef(base = dir, id = dir.name): ClasspathDep[ProjectReference]
}:_*)
}
}
This checks your project directory for a checkouts
directory, and if it exists, adds the directories therein (which should be symlinks to other projects) as project references to the project. It expects the symlink to be named like the actual ID of the linked project (e.g. default-edd2f8
or bar
). If the directory doesn't exist, the build just works as before.
When you add or remove a symlink in the checkouts directory (or the directory itself), you must reload the Foo project to pick up the changes.
Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…