我在多项目build.sbt中初始化常用设置,如下所示:
lazy val commonSettings = Seq( version := "0.1", ..)
..
lazy val libs = Seq( "org.some" % "somelib" % "1.2.3", ..)
..
lazy val myProject = Project(..).
settings(commonSettings, version := "0.2", libraryDependencies ++= libs)
鉴于
的定义sbt.Project.settings(ss: Setting[_]*)
我很困惑这实际上有效,因为我在这里混合了Setting[_]
和Seq[Setting[_]]
args。我错过了什么,扁平化发生在哪里?
答案 0 :(得分:3)
从sbt 0.13.8
开始,定义更改为:
def settings(ss: SettingsDefinition*): Project =
copy(settings = (settings: Seq[Setting[_]]) ++ ss.flatMap(_.settings))
这是展平的地方,SettingsDefinition
定义为:
sealed trait SettingsDefinition {
def settings: Seq[Setting[_]]
}
sealed class Setting[T] private[Init] (
val key: ScopedKey[T], val init: Initialize[T], val pos: SourcePosition
) extends SettingsDefinition {
def settings = this :: Nil
...
}
final class SettingList(val settings: Seq[Setting[_]]) extends SettingsDefinition
object SettingsDefinition {
...
implicit def wrapSettingsDefinition(ss: Seq[Setting[_]]): SettingsDefinition =
new SettingList(ss)
}
注意:
SettingsDefinition
Seq[Setting[_]]
都会被自动提升为SettingsDefinition
。