Skip to content

Instantly share code, notes, and snippets.

@teamon
Created September 13, 2012 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teamon/3717948 to your computer and use it in GitHub Desktop.
Save teamon/3717948 to your computer and use it in GitHub Desktop.

Multiproject sbt configuration with separate build files

root
 |- sub1
 |- sub2
  • root aggregates sub1 and sub2
  • sub1 depends on sub2

Build files

  • project/Build.scala
import sbt._
import Keys._

object RootBuild extends Build {
  lazy val root = Project("root", file(".")).aggregate(sub1, sub2)
  lazy val sub1 = Project("sub1", file("sub1")).dependsOn(sub2)
  lazy val sub2 = Project("sub2", file("sub2"))
}
  • sub1/build.sbt
name := "sub1-lib"

organization := "dupa"
  • sub2/build.sbt
name := "sub2-lib"

Let's run $ sbt

> project root
[info] Set current project to root (in build file:/Users/teamon/tmp/scratch-1347572239/root/)
> name
[info] sub1/*:name
[info]  sub1-lib
[info] sub2/*:name
[info]  sub2-lib
[info] root/*:name
[info]  root

Compiling root compiles all three projects

> compile
[info] Updating {file:/Users/teamon/tmp/scratch-1347572239/root/}sub2...
[info] Updating {file:/Users/teamon/tmp/scratch-1347572239/root/}root...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Updating {file:/Users/teamon/tmp/scratch-1347572239/root/}sub1...
[info] Done updating.
[info] Resolving sub2-lib#sub2-lib_2.9.1;0.1-SNAPSHOT ...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[success] Total time: 0 s, completed Sep 13, 2012 11:44:56 PM

Project sub1 has organization set form it's build.sbt file

> project sub1
[info] Set current project to sub1-lib (in build file:/Users/teamon/tmp/scratch-1347572239/root/)
> name
[info] sub1-lib
> organization
[info] dupa

And compiling sub1 will compile sub2

> compile
[info] Updating {file:/Users/teamon/tmp/scratch-1347572239/root/}sub2...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[info] Updating {file:/Users/teamon/tmp/scratch-1347572239/root/}sub1...
[info] Resolving sub2-lib#sub2-lib_2.9.1;0.1-SNAPSHOT ...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[success] Total time: 0 s, completed Sep 13, 2012 11:45:11 PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment