【问题标题】:accessing dependent (not child) projects in sbt plugin访问 sbt 插件中的依赖(非子)项目
【发布时间】:2017-10-17 15:47:50
【问题描述】:

请在下面找到使用我们插件的示例 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 插件中访问依赖项目。

【问题讨论】:

  • val deps = thisProject.value.dependencies.map { dep => dep.project }?
  • 我想你不小心忘了包括你的问题
  • @Micro : 请在答案部分添加您的评论,以便接受它:)
  • @Martijn :按照建议更新问题
  • @mogli 完成 ;-)

标签: dependencies sbt sbt-plugin


【解决方案1】:

要获取项目的依赖项

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

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

【讨论】:

    猜你喜欢
    • 2018-03-25
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 2011-12-16
    • 2011-05-30
    • 1970-01-01
    • 2016-03-19
    • 2014-02-25
    相关资源
    最近更新 更多