访问sbt插件中的依赖(非子)项目

时间:2017-05-18 02:05:52

标签: dependencies sbt sbt-plugin

请在下面找到使用我们插件的示例build.sbt文件。 在这个示例BasePlugin中,我们想要一个/ project,b / project目录的完整路径: -

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)

另外,请在下面找到简化的sbt插件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) }
    }
  )
}

如何在sbt插件中访问依赖项目。

1 个答案:

答案 0 :(得分:0)

要获取项目的依赖项

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

如果您在thisProject方法正文中访问projectSettings,这将按预期工作。