1

我正在使用插件sbt-assembly(版本 0.13.0),我想根据某些情况来调用assemblyPackageDependency或不调用appendContentHashInputKey

基本上,我想做这样的事情:

lazy val isGlobalCached = InputKey[Boolean]("")

lazy val myTask = taskKey[sbt.File]("myTask")

myTask := {
    if (isGlobalCached.value)
        //run with the modified assemblyOption
        //assemblyOption in assemblyPackageDependency ~= { x => x.copy(appendContentHash = true) }
        assemblyPackageDependency.value
    else
        assemblyPackageDependency.value
}

但我不知道如何设置assemblyOption只有条件为真,而不是全局


以下是我尝试过的一些不起作用的事情:

lazy val isGlobalCached = InputKey[Boolean]("")

lazy val myTask = taskKey[sbt.File]("myTask")

lazy val assemblyPackageDependencyWithHash = taskKey[sbt.File]("assemblyPackageDependencyWithHash")


assemblyPackageDependencyWithHash <<= assemblyPackageDependency
assemblyOption in assemblyPackageDependencyWithHash ~= { x => x.copy(appendContentHash = true) }

myTask := {
    //run with the modified assemblyOption
    if (isGlobalCached.value)
        assemblyPackageDependencyWithHash.value
    else
        assemblyPackageDependency.value
}

和:

lazy val isGlobalCached = InputKey[Boolean]("")

lazy val myTask = taskKey[sbt.File]("myTask")

lazy val globalCacheConf = config("globalCacheConf")

assemblyOption  in globalCacheConf := (assemblyOption in assemblyPackageDependency).value.copy(appendContentHash = true)

myTask := {
    //run with the modified assemblyOption
    if (isGlobalCached.value)
        assemblyPackageDependency.in(globalCacheConf).value
    else
        assemblyPackageDependency.value
}
4

1 回答 1

1
import complete.DefaultParsers._

val myCmd : Command = Command("myCmd")(_ => Space ~> Bool) { (state, globalCached) =>
  val extracted = Project extract state
  import extracted._
  Project.runTask(
    assemblyPackageDependency,
    append(Seq(assemblyOption in assemblyPackageDependency := globalCached), state)
  )
  state
}

commands += myCmd
于 2015-09-10T03:53:30.167 回答