Skip to content

Instantly share code, notes, and snippets.

@JasonStoltz
Created July 8, 2014 13:16
Show Gist options
  • Save JasonStoltz/988bc09169ae7e792867 to your computer and use it in GitHub Desktop.
Save JasonStoltz/988bc09169ae7e792867 to your computer and use it in GitHub Desktop.
Accessing settings from another project in an sbt task
lazy val webAggregateImpl = webAggregate := { mappings: Seq[PathMapping] =>
def go(m: Seq[PathMapping], p: ResolvedProject): Seq[(File, String)] = {
if (p.dependencies.isEmpty) {
m
} else {
p.dependencies.map({ dep =>
val subp = Project.getProjectForReference(dep.project, buildStructure.value).get
/*
At this point I have a http://www.scala-sbt.org/0.12.4/api/sbt/ResolvedProject.html ... so I can access project
certain properties of the project, like base, id, etc.
However, that's pretty limiting. I'd like to be able to access ANY setting from the project. So one way I tried to
do that is to get the ProjectRef and access in with "in", like:
val temp = (target in dep.project).value ... but that fails with the exception:
error: Illegal dynamic reference: dep
val temp = (target in dep.project).value
^
*/
val newFiles = (subp.base / "app" / "assets" / "js").***.get.toSet
val newMappings: Seq[(File, String)] = newFiles pair relativeTo(subp.base / "app" / "assets")
go(m ++ newMappings, subp)
}).flatten
}
}
val newMappings = go(mappings, thisProject.value).distinct
SbtWeb.syncMappings(
streams.value.cacheDirectory,
newMappings,
WebKeys.webTarget.value / webAggregate.key.label
)
newMappings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment