How do I refer to a baseDirectory
of a root project from within sub-projects in a multi-project sbt build? 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). So you can use the in
operator to access the value of a setting in another project. To get the value of the baseDirectory
setting key in the project full
, you would write
(baseDirectory in full).value
Hence, your complete javaSource
setting should be:
javaSource in Compile := (baseDirectory in full).value / "foo" / "src"
See the documentation on Scopes in sbt for the whole story.
(Note that accessing the settings
method of a Project
rarely does what one wants. I believe it is only relevant when write custom commands .)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.