Reputation: 2114
I am writing a task to package several but not all subprojects together, and am using a setting for exclusion and task.all(scope filter)
to select projects. However sbt keeps say References undefined settings at runtime
.
Here is project/build.scala I use followed by the error I need your advice on:
import sbt._
import Keys._
object build extends Build {
lazy val root = Project(
id = "root",
base = file("."),
aggregate = Seq(a,b),
settings = Seq(
exclude := Seq(a),
module := moduleImpl.value,
modules := modulesImpl.value
)
)
lazy val a = Project(
id = "a",
base = file("a")
)
lazy val b = Project(
id = "b",
base = file("b")
)
val exclude = settingKey[Seq[ProjectReference]]("excludes")
val module = taskKey[String]("module")
val modules = taskKey[Seq[String]]("modules")
def moduleImpl = Def.task {
projectID.value.organization
}
def modulesImpl = Def.taskDyn {
module.all(ScopeFilter(inAggregates(ThisProject) -- inProjects(exclude.value: _*)))
}
}
This is the error that I really want to get rid of:
> show modules
[trace] Stack trace suppressed: run last root/*:modules for the full output.
[error] (root/*:modules) sbt.Init$RuntimeUndefined: References to undefined settings at runtime.
[error] Total time: 0 s, completed 2014-06-12 16:48:05
Any idea to fix this?
Upvotes: 1
Views: 434
Reputation: 13749
The sbt complains, because the task you're using is not defined in the sub-projects.
The solution would be not to call it on module
, but on moduleImpl
lazy val moduleImpl = Def.task {
projectID.value.organization
}
def modulesImpl = Def.taskDyn {
moduleImpl.all(ScopeFilter(inAggregates(ThisProject) -- inProjects(exclude.value: _*)))
}
PS. When you do
Project(
id = "root",
base = file("."),
aggregate = Seq(a,b),
settings = Seq(
exclude := Seq(a),
module := moduleImpl.value,
modules := modulesImpl.value
)
)
You override all the default settings. You may want to add them with Defaults.defaultSettings
or use settings
method on the Project
.
Upvotes: 1