如何在多项目sbt构建中的子项目中引用根项目的baseDirectory
?像
lazy val full: Project = Project(
id = "full",
base = file("."),
..
)
lazy val sub = Project(
id = "sub",
base = file("sub"),
..
settings = Seq(
javaSource in Compile := full.settings.baseDirectory / "foo" / "src"
)
)
这次尝试只是给了我:
: error: ambiguous reference to overloaded definition,
both method settings in trait Project of type (ss: sbt.Def.Setting[_]*)sbt.Project
and method settings in trait ProjectDefinition of type => Seq[sbt.Def.Setting[_]]
match expected type ?
javaSource in Compile := full.settings.baseDirectory / "foo" / "src",
^
答案 0 :(得分:4)
在sbt中,项目只是另一个设置轴(以及配置和任务)。因此,您可以使用in
运算符来访问另一个项目中的设置值。要获取项目baseDirectory
中full
设置键的值,您需要编写
(baseDirectory in full).value
因此,您的完整javaSource
设置应为:
javaSource in Compile := (baseDirectory in full).value / "foo" / "src"
有关整个故事,请参阅Scopes in sbt上的文档。
(请注意,访问settings
的{{1}} 方法很少能满足您的需求。我相信只有在编写自定义命令。)