I\'m trying to implement an sbt task which collects all the source directories of projects specified using dependsOn
method of a project. I end up with this piece o
I've been struggling with a similar problem but finally found an answer.
So, what you may do is to define a dynamic task performing your complex computation, like
val buildMaping: Def.Initialize[Task[Seq[Def.Initialize[(ProjectRef, Seq[Seq[File]])]]]] = {
Def.taskDyn {
val refs = loadedBuild.value.allProjectRefs
val tt = refs.map(_._1).map {
ref =>
sourceDirectories.all(ScopeFilter(inProjects(ref)))
.zipWith(Def.setting(ref)) { case (a, b) => b -> a }
}
Def.task {
tt
}
}
}
So, this buildMapping
allows you to get a map of project references to their source directories.
then invoke your task this way:
Def.task {
val sd = settingsData.in(Global).value
val mapping = buildMaping.value.map(_.evaluate(sd)).toMap
val allProjectRefs = loadedBuild.value.allProjectRefs.map(_._1)
//... now you may iterate over each project,
// get deps and use the mapping to resolve your values
}