【发布时间】:2012-04-29 22:14:53
【问题描述】:
从quick-install 命令(在我正在编写的 sbt 插件中定义)中运行package 任务时,我试图暂时跳过编译任务。我可以通过将skip 设置放在compile 任务上来跳过所有编译,但这会导致所有compile 任务被跳过:
object MyPlugin extends Plugin {
override lazy val settings = Seq(
(skip in compile) := true
)
...
}
我只需要在运行quick-install 命令时跳过compile。有没有办法临时修改设置,或者将其范围仅限于我的快速安装命令?
我尝试了一个设置转换(基于https://github.com/harrah/xsbt/wiki/Advanced-Command-Example),它应该将skip := false 的所有实例替换为skip := true,但它没有任何效果(即转换后仍会发生编译):
object SbtQuickInstallPlugin extends Plugin {
private lazy val installCommand = Command.args("quick-install", "quick install that skips compile step")(doCommand(Configurations.Compile))
override lazy val settings = Seq(
commands ++= Seq(installCommand),
(Keys.skip in compile) := false // by default, don't skip compiles
)
def doCommand(configs: Configuration*)(state: State, args: Seq[String]): State = {
val extracted = Project.extract(state)
import extracted._
val oldStructure = structure
val transformedSettings = session.mergeSettings.map(
s => s.key.key match {
case skip.key => { skip in s.key.scope := true } // skip compiles
case _ => s
}
)
// apply transformed settings (in theory)
val newStructure = Load.reapply(transformedSettings, oldStructure)
Project.setProject(session, newStructure, state)
...
}
知道我缺少什么和/或更好的方法吗?
编辑:
跳过设置是一个任务,所以一个简单的解决方法是:
object SbtQuickInstallPlugin extends Plugin {
private lazy val installCommand = Command.args("quick-install", "quick install that skips compile step")(doCommand(Configurations.Compile))
private var shouldSkipCompile = false // by default, don't skip compiles
override lazy val settings = Seq(
commands ++= Seq(installCommand),
(Keys.skip in compile) := shouldSkipCompile
)
def doCommand(configs: Configuration*)(state: State, args: Seq[String]): State = {
shouldSkipCompile = true // start skipping compiles
... // do stuff that would normally trigger a compile such as running the packageBin task
shouldSkipCompile = false // stop skipping compiles
}
}
我不相信这是最强大的解决方案,但它似乎可以满足我的需要。
【问题讨论】:
标签: sbt