[英]Referring to a setting in an sbt root project from a sub project
How do I refer to a baseDirectory
of a root project from within sub-projects in a multi-project sbt build? 如何从多项目sbt构建中的
baseDirectory
中引用根项目的baseDirectory? Like 喜欢
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"
)
)
This attempt just gives me: 这个尝试只是给了我:
: 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",
^
In sbt, projects are just another setting axis (along with configurations and tasks). 在sbt中,项目只是另一个设置轴 (以及配置和任务)。 So you can use the
in
operator to access the value of a setting in another project. 因此,您可以使用
in
运算符来访问另一个项目中的设置值。 To get the value of the baseDirectory
setting key in the project full
, you would write 要获取的值
baseDirectory
在项目设置键full
,你会写
(baseDirectory in full).value
Hence, your complete javaSource
setting should be: 因此,您的完整
javaSource
设置应该是:
javaSource in Compile := (baseDirectory in full).value / "foo" / "src"
See the documentation on Scopes in sbt for the whole story. 有关整个故事,请参阅sbt中有关Scopes的文档。
(Note that accessing the settings
method of a Project
rarely does what one wants. I believe it is only relevant when write custom commands .) (注意,在访问
settings
一个的方法, Project
很少做自己想要的东西,我相信只有当写自定义命令有关。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.