Skip to content

Instantly share code, notes, and snippets.

@ltackmann
Created November 7, 2011 11:47
Show Gist options
  • Save ltackmann/1344760 to your computer and use it in GitHub Desktop.
Save ltackmann/1344760 to your computer and use it in GitHub Desktop.
Task that aggregate resources from dependencies in SBT 0.11
import sbt._
import Keys._
object ProjectBuild extends Build {
// setup sub projects
// ...
lazy val warproj = Project("war-project", file("."), settings = buildSettings) dependsOn(subproj1, subproj2 /* ... */)
val buildSettings = {
// libraryDependencies += ...,
// other stuff,
// add task that aggregates resources from dependencies
Seq(aggrResTask)
}
val aggrRes= TaskKey[Seq[File]]("aggr-res", "show aggregate resources")
val aggrResTask = aggrRes in Compile <<= {
(thisProjectRef, buildStructure) flatMap aggrResources(resources in Compile)
}
def aggrResources[T](key: ScopedTask[Seq[T]])(proj: ProjectRef, struct: Load.BuildStructure) = {
val deps = collectDeps(_.dependencies.map(_.project))(proj, struct)
deps.flatMap(key in (_, Compile) get struct.data).join.map(_.flatten)
}
def collectDeps(op: ResolvedProject => Seq[ProjectRef])(projRef: ProjectRef, struct: Load.BuildStructure): Seq[ProjectRef] = {
val deps = Project.getProject(projRef, struct).toSeq.flatMap(op)
deps.flatMap(ref => ref +: collectDeps(op)(ref, struct)).distinct
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment