Skip to content

Instantly share code, notes, and snippets.

@pfn
Last active December 19, 2015 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfn/5872427 to your computer and use it in GitHub Desktop.
Save pfn/5872427 to your computer and use it in GitHub Desktop.
multi-project build example: 2 common libraries, and 3 application projects. All projects are java.
import sbt._
import sbt.Keys._
import android.Keys._
object ExampleMultiBuild extends Build {
// define a new task
val release = TaskKey[Unit]("release", "build & release all release builds")
// setup an aggregate for 'install' and 'release'
// calling either will perform the install or release operation against
// all 3 applications
lazy val root = Project(id = "top", base = file(".")) settings(
android.Plugin.androidCommands :+
(install <<= ( // install all apps
install in (foo, Android),
install in (baz, Android),
install in (bar, Android)) map { (_,_,_) => () }) :+
(release <<= (
packageRelease in (foo, Android),
packageRelease in (baz, Android),
packageRelease in (bar, Android)) map { (_,_,_) => () }): _*
) aggregate(core, common, foo, baz, bar)
// define a core library
lazy val core = Project(
id = "corelib", base = file("CoreLibrary")) settings(
android.Plugin.androidBuild: _*)
// define a common library
lazy val common = Project(
id = "commonlib", base = file("CommonLibrary")) settings(
commonlibSettings: _*) dependsOn(core)
// define the 3 end-application projects
lazy val foo = Project(
id = "foo-app", base = file("FooProject")) settings(commonSettings: _*) dependsOn(common)
lazy val bar = Project(
id = "bar", base = file("BarProject")) settings(commonSettings: _*) dependsOn(common)
lazy val baz = Project(
id = "baz", base = file("BazProject")) settings(commonSettings: _*) dependsOn(common)
// declare settings for commonlib
// 'watchSources' is modified so that .swp files don't cause resources
// to rebuild while viewing with vim (but not saving)
lazy val commonlibSettings = android.Plugin.androidBuild(core) ++ Seq(
watchSources ~= { _.filterNot(_.isDirectory) },
javacOptions += "-Xlint:deprecation")
// declare common settings for the foo, bar and baz projects
// notice the use of androidBuild(core, common) to define the
// compile dependency on those projects
lazy val commonSettings = android.Plugin.androidBuild(core, common) ++ Seq(
run <<= run in Android,
javacOptions += "-Xlint:deprecation")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment