Skip to content

Instantly share code, notes, and snippets.

@matanox
Created October 23, 2015 13:08
Show Gist options
  • Save matanox/15f5cfef3312525e18dc to your computer and use it in GitHub Desktop.
Save matanox/15f5cfef3312525e18dc to your computer and use it in GitHub Desktop.
multi-project sbt build definition, involving dependent compiler and sbt plugins
val integrationTest = taskKey[Unit]("Executes integration tests.")
lazy val root = (project in file(".")).aggregate(simpleGraph, compilerPluginUnitTestLib, compilerPluginn, canveSbtPlugin, sbtPluginTestLib).enablePlugins(CrossPerProjectPlugin).settings(
scalaVersion := "2.11.7",
crossScalaVersions := Seq("2.10.4", "2.11.7"),
publishArtifact := false, // no artifact to publish for the virtual root project
integrationTest := (run in Compile in sbtPluginTestLib).value // not working: need to bounty http://stackoverflow.com/questions/33291071/invoking-a-subprojects-main-with-a-custom-task
)
lazy val simpleGraph = (project in file("simpleGraph"))
lazy val compilerPluginUnitTestLib = (project in file("compiler-plugin-unit-test-lib"))
lazy val compilerPluginn = (project in file("compiler-plugin")).settings(
name := "compiler-plugin",
organization := "canve",
version := "0.0.1",
isSnapshot := true, // to enable overwriting the existing artifact version
scalaVersion := "2.11.7",
crossScalaVersions := Seq("2.10.4", "2.11.7"),
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
"org.scala-lang" % "scala-library" % scalaVersion.value % "provided",
"com.github.tototoshi" %% "scala-csv" % "1.2.2",
//"com.github.tototoshi" %% "scala-csv" % "1.3.0-SNAPSHOT", // snapshot version might be causing sbt/ivy going nuts
//"org.apache.tinkerpop" % "tinkergraph-gremlin" % "3.0.1-incubating",
//"canve" %% "simple-graph" % "0.0.1",
//"canve" %% "compiler-plugin-unit-test-lib" % "0.0.1" % "test",
"com.lihaoyi" %% "utest" % "0.3.1" % "test"
),
testFrameworks += new TestFramework("utest.runner.Framework"),
/*
* take care of including all non scala core library dependencies in the build artifact
*/
test in assembly := {},
jarName in assembly := name.value + "_" + scalaVersion.value + "-" + version.value + "-assembly.jar",
assemblyOption in assembly ~= { _.copy(includeScala = false) },
packagedArtifact in Compile in packageBin := {
val temp = (packagedArtifact in Compile in packageBin).value
println(temp)
val (art, slimJar) = temp
val fatJar = new File(crossTarget.value + "/" + (jarName in assembly).value)
val _ = assembly.value
IO.copy(List(fatJar -> slimJar), overwrite = true)
println("Using sbt-assembly to package library dependencies into a fat jar for publication")
(art, slimJar)
}
).dependsOn(simpleGraph, compilerPluginUnitTestLib)
lazy val canveSbtPlugin = (project in file("sbt-plugin")).settings(
organization := "canve",
name := "sbt-plugin",
isSnapshot := true, // to enable overwriting the existing artifact version
scalaVersion := "2.10.4",
crossScalaVersions := Seq("2.10.4"),
sbtPlugin := true
//resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
//libraryDependencies ++= Seq("com.github.tototoshi" %% "scala-csv" % "1.3.0-SNAPSHOT")
).dependsOn(compilerPluginn)
lazy val sbtPluginTestLib = (project in file("sbt-plugin-test-lib")).settings(
name := "sbt-plugin-test-lib",
organization := "canve",
version := "0.0.1",
/*
* this project is purely running sbt as an OS process, so it can use latest scala version not sbt's scala version,
* and there is no need whatsoever to provided a cross-compilation of it for older scala.
*/
scalaVersion := "2.11.7",
crossScalaVersions := Seq("2.11.7"),
/*
* The following resolver is added as a workaround: the `update task` of this subproject,
* may oddly enough try to resolve scala-csv, which in turn may fail if the resolver for it is not in scope here.
*/
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided", // otherwise cannot use scala.tools.nsc.io.File
"org.fusesource.jansi" % "jansi" % "1.4"
),
publishArtifact := false,
(run in Compile) <<= (run in Compile).dependsOn(publishLocal in canveSbtPlugin)
).dependsOn(compilerPluginn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment