在sbt插件中访问相关项目(非子项目) [英] accessing dependent (not child) projects in sbt plugin
本文介绍了在sbt插件中访问相关项目(非子项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请在下面找到使用我们的插件的示例build.sbt文件。
在此示例BasePlugin中,我们想要完整路径到a / project,b / project目录:-
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)
此外,在下面找到简化的sbt插件BasePlugin.scala:-
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) }
}
)
}
如何在sbt插件中访问依赖项目。
How to access dependent projects in sbt plugin.
推荐答案
要获取项目的依赖项,
val deps = thisProject.value.dependencies.map {dep => dep.project}
如果您在其中访问 thisProject
,这将按预期工作 projectSettings
方法的主体。
This will work as expected if you are accessing thisProject
within the projectSettings
method's body.
这篇关于在sbt插件中访问相关项目(非子项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文