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/5872679 to your computer and use it in GitHub Desktop.
Save pfn/5872679 to your computer and use it in GitHub Desktop.
Another java-based multi-project build example. 1 java library project, 2 android library projects, 1 test project, 1 use of the actionbarsherlock apklib and 1 android project.
import sbt._
import sbt.Keys._
import android.Keys._
import android.Dependencies.apklib
object ExampleMultiBuild extends Build {
// add 'run' alias to the root project
lazy val root = Project(id = "root-prj", base = file(".")) settings(
android.Plugin.androidCommands ++ Seq(
run <<= (run in (mainprj, Android)) map { _ => Unit }): _*
) aggregate(javalib, alib, slidingmenu, mainprj)
lazy val javalib = Project(id = "java-lib", base = file("AJavaLib")) settings(
// use an ant/eclipse style layout
javaSource in Compile <<= baseDirectory (_/"src"),
javacOptions in Compile ~= { _ ++ Seq("-source", "1.5", "-target", "1.5") },
// android projects consume java jars, export it with this setting
exportJars := true
)
// our project has a weird layout, include guava from another project
lazy val alib = Project(
id = "andylib", base = file("AnAndroidLibrary")) settings((
commonSettings :+ (unmanagedClasspath in Compile ~= {
Attributed.blank(mainprj.base / "libs" / "guava-14.0.1.jar") +: _ })
):_*) dependsOn(javalib)
// the main project loads actionbarsherlock via an apklib
lazy val mainprj: Project = Project(
id = "main", base = file("MainAndroidProject")) settings(Seq(
resolvers <+= (sdkPath in Android) { p =>
"gms" at (file(p) / "extras" / "google" / "m2repository").toURI.toString
},
libraryDependencies ++= Seq(
apklib("com.actionbarsherlock" % "actionbarsherlock" % "4.2.0"),
aar("com.google.android.gms" % "play-services" % "3.1.36")
)
) ++ commonSettings: _*) dependsOn(alib, slidingmenu)
lazy val tests = Project(
id = "tests", base = file("SomeJvmBasedUnitTests")) settings(
// this project has an eclipse/ant-style layout
javaSource in Test <<= baseDirectory (_/"src"),
libraryDependencies ++= Seq(
"junit" % "junit" % "4.11" % "test",
"com.novocode" % "junit-interface" % "0.10-M4" % "test"
)
) dependsOn(mainprj)
// another android library
lazy val slidingmenu = Project(
id = "smenu", base = file("SlidingMenu/library")) settings(
commonSettings: _*)
// this project configuration doesn't require specifying arguments to
// androidBuild due to the way it's setup, but specifying them is harmless.
lazy val commonSettings = android.Plugin.androidBuild :+
(watchSources ~= { _.filterNot(_.isDirectory) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment