将Seq [Setting [_]]作为Project.settings()args之一传递

时间:2015-06-24 23:38:05

标签: scala sbt

我在多项目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。我错过了什么,扁平化发生在哪里?

1 个答案:

答案 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