我正在使用插件sbt-assembly
(版本 0.13.0),我想根据某些情况来调用assemblyPackageDependency
或不调用appendContentHash
InputKey
基本上,我想做这样的事情:
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
}