Reputation: 3
I have a variable libDir defined in Global & when I try to use it inside one of the sub-projects (with specifying the scope), it fails with:
[info] Loading project definition from /Users/chichu/ws/tip/TestMain/project References to undefined settings:
*/*:libDir from Streaming/*:install (/Users/chinchu/ws/tip/TestMain/build.sbt:124) Did you mean TestRoot/*:libDir ?
Here's the snippet from build.sbt:
===
def Streaming(name: String, dir: String, archiveName: String, main: String): Project = { ... ...
install := {
val jarName = assembly.value
sbt.IO.copyFile(jarName, (libDir in Global).value) // copy over the jar
}
}
.. ..
lazy val installDir = SettingKeyFile
libDir := baseDirectory.value / "install/lib"
==
Why is it not able to resolve "libDir" even when I specify "in Global" ? I also tried "libDir in TestRoot" & it reports "error: not found: value TestRoot"
Thanks -C
Upvotes: 0
Views: 767
Reputation: 13749
The specification says, that if you define a setting like this:
libDir := baseDirectory.value / "install/lib"
It will set a task and a configuration scope to Global
, but a project scope will be set to current project (that is a root project in your case).
When you refer to your setting as libDir in Global
, you set configuration scope to Global
but still, you are in the current build, that is some project, that tries to define the install
setting.
You should define your libDir
like this:
libDir in Global := baseDirectory.value / "install/lib"
which will set also the project scope to Global
.
lazy val installDir = settingKey[File]("ff")
lazy val install = taskKey[Unit]("prints install")
installDir in Global := baseDirectory.value / "install/lib"
val projectA = project.in(file("projectA")).settings(
install := {
val install = (installDir in Global).value
println(install)
}
)
val projectB = project
Alternatively you could give a root project an explicit id, that is in your main build.sbt
add a line
val root = Project("root", file("."))
then in your install
task refer to Global
in that project (root
is a name of the project)
(libDir in Global in root).value
lazy val installDir = settingKey[File]("ff")
lazy val install = taskKey[Unit]("prints install")
installDir := baseDirectory.value / "install/lib"
lazy val root = Project("root", file("."))
lazy val projectA = project.in(file("projectA")).settings(
install := {
val install = (installDir in Global in root).value
println(install)
}
)
lazy val projectB = project
Upvotes: 2