新SBT设置值不起作用

时间:2018-05-22 16:55:24

标签: scala sbt

我在Tasks对象

中定义了一个设置键
object Tasks {

  lazy val shouldCheckSnapshotDeps: SettingKey[Boolean] = settingKey[Boolean](
    "Should enforce SNAPSHOT check 'checkSnapshotDependencies'"
  )

  lazy val checkSnapshotDependencies: TaskKey[Unit] = taskKey[Unit](
    "Checks for SNAPSHOT dependencies and raise exception if any"
  )

  class SnapshotDepsException(message: String) extends FeedbackProvidedException

  lazy val checkSnapshotDependenciesTask: Def.Initialize[Task[Unit]] = Def.task {
    val moduleIds = (managedClasspath in Runtime).value.flatMap(_.get(moduleID.key))
    val snapshotModules = moduleIds.filter(m => m.isChanging || m.revision.endsWith("-SNAPSHOT"))

    if (snapshotModules.nonEmpty && shouldCheckSnapshotDeps.value) {
      val message = s"Found SNAPSHOT versions for ${snapshotModules.mkString(System.lineSeparator())}." +
        s" SNAPSHOTS are not allowed. Set settings for 'shouldCheckSnapshotDeps' to suppress this check"
      sys.error(message)
      throw new SnapshotDepsException(message)
    }
  }
}

我尝试使用sbt 'set Tasks.shouldCheckSnapshotDeps := false'设置值。但是,使用命令行设置的新设置值似乎不会生效。我也在下面的日志中看到,

[info] Defining root/*:shouldCheckSnapshotDeps
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...

The new value will be used by no settings or tasks.行似乎传达了我的问题。

使用

设置设置的默认值
shouldCheckSnapshotDeps := true,
checkSnapshotDependencies := checkSnapshotDependenciesTask.value

为什么使用sbt 'set Tasks.shouldCheckSnapshotDeps := false'设置的新设置值无效?

Task.scala位于文件系统中的project/Task.scala

0 个答案:

没有答案