简体   繁体   English

如何在多项目构建中获取另一个项目的设置值

[英]How to get setting value of another project in multi-project build

I`m not sure that I get right the concept of sbt workflow.我不确定我是否正确理解了 sbt 工作流程的概念。 I have multi-project structure of an arbitrary depth in my build.sbt Now I want to define task which can show me library dependencies of project current subprojects depends on.我的构建中有任意深度的多项目结构。sbt 现在我想定义可以显示项目当前子项目所依赖的库依赖项的任务。 Or, in common: is there any way to get setting value of another project?或者,共同点:有没有办法获得另一个项目的设定值?

I`m trying to do somthing like this:我正在尝试做这样的事情:

val hierarchyDeps = taskKey[Seq[ModuleID]]("")
val hierarchyDepsImpl = Def.task {
  loadedBuild.value.allProjectRefs.flatMap { case (projectRef, resolvedProject) =>
    (projectRef / libraryDependencies).value
  }
}

val cmn = project.in(file("cmn"))
val subA = project.in(file("sub_a")).dependsOn(cmn).settings(hierarchyDeps := hierarchyDepsImpl.value)
val subB = project.in(file("sub_b")).dependsOn(cmn).settings(hierarchyDeps := hierarchyDepsImpl.value)

but getting java.lang.IllegalArgumentException :但得到java.lang.IllegalArgumentException

java.lang.IllegalArgumentException: Could not find proxy for val projectRef: sbt.ProjectRef in List(value projectRef, value $anonfun, method $anonfun$hierarchyDepsImpl$1, value hierarchyDepsImpl, object $5879c5c8d08c0b0b007a, package <empty>, package <root>) (currentOwner= value hierarchyDepsImpl )

I think you are trying to do something outside of sbt philosophy.我认为您正在尝试在 sbt 哲学之外做一些事情。

You should define a task for each project that does something.你应该为每个做某事的项目定义一个任务。 Then add aggregate to your root project with the list of all sub-projects.然后使用所有子项目的列表将aggregate添加到您的根项目中。 Thus, when you call sbt taskName , it will call taskName for all sub-projects in aggregate .因此,当您调用sbt taskName时,它将为所有子项目调用taskName aggregate

Also, what you want to do can be just done with following另外,您想做的事情可以通过以下方式完成

sbt "show libraryDependencies"

given that you defined aggregate for your root project假设您为根项目定义了aggregate

val root = project.in(file(".")).aggregate(cmn, subA, subB)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM