仅在满足条件时定义设置

时间:2016-05-19 15:25:20

标签: scala sbt

有关条件设置的问题。我只是在满足某个条件时才尝试定义设置:

lazy val proj = project .settings(/*other settings...*/) .settings((if (condition) Seq(foo := bar.value) else Seq.empty): _*)

除此之外,如果我可以在个人设定的基础上做到这一点,我的代码看起来会更加清晰,例如:

project.settings( // other settings... if (condition) (foo := bar.value) else (hole := Nil) // other settings... )

有没有任何整洁和可接受的方式来实现这一目标?什么是“幺半零”设置的好候选人?

1 个答案:

答案 0 :(得分:2)

您可以使用.configure

val prj = project.settings(...).configure { p =>
  if (foo) {
    p.settings(...)
  } else p
}
相关问题