accessing dependent (not child) projects in sbt plugin

帅比萌擦擦* 提交于 2019-12-12 06:07:21

问题


Please find below sample build.sbt file that uses our plugin. In this sample BasePlugin, we want to full path to a/project, b/project directory :-

import sbt._
import Keys._
import BasePlugin._


BasePlugin.settings

lazy val root = Project("root", file(".")).dependsOn(
                                                    ProjectRef( uri("../some/where/a"), "a" ),
                                                    ProjectRef( uri("../some/where/b"), "b" )
                                                )       




enablePlugins(BasePlugin)

Also, find below, simplified sbt plugin BasePlugin.scala :-

package base

import sbt.{ThisBuild, Def, TaskKey, AutoPlugin}
import sbt._
import Keys._

/**
 * Created by mogli on 4/23/2017.
 */
object BasePlugin extends AutoPlugin {

  object autoImport {
    lazy val customtask: TaskKey[Unit] = TaskKey("customtask")
  }

  import autoImport.customtask


  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    customtask := {
      //expectation: to get an iterator or collection sort of thing for dependent projects, but they are not in this variable (projectDependencies)
      val deps = projectDependencies
      deps map { c => println("project : " + c) }
    }
  )
}

How to access dependent projects in sbt plugin.


回答1:


To get the project's dependencies do

val deps = thisProject.value.dependencies.map { dep => dep.project }

This will work as expected if you are accessing thisProject within the projectSettings method's body.



来源:https://stackoverflow.com/questions/44037424/accessing-dependent-not-child-projects-in-sbt-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!