0

请在下面找到使用我们插件的示例 build.sbt 文件。在这个示例 BasePlugin 中,我们想要 a/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 插件中的依赖项目。

4

1 回答 1

0

获取项目的依赖项

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

thisProject如果您在projectSettings方法的主体内访问,这将按预期工作。

于 2017-05-23T05:08:01.873 回答