How to get source directories of all project dependencies of an sbt project?

后端 未结 1 1554
[愿得一人]
[愿得一人] 2021-01-25 01:24

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

相关标签:
1条回答
  • 2021-01-25 01:59

    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
    }
    
    0 讨论(0)
提交回复
热议问题