如何临时跳过在自定义sbt命令中运行编译任务?
在如何临时跳过在自定义sbt命令中运行编译任务?,sbt,Sbt,在快速安装命令(在我编写的sbt插件中定义)中运行包任务时,我试图暂时跳过编译任务。通过将skip设置置于compile任务上,我可以跳过所有编译,但这会导致跳过所有compile任务: object MyPlugin extends Plugin { override lazy val settings = Seq( (skip in compile) := true ) ... } 我只需要在运行快速安装命令时跳过编译。是否有方法临时修改设置,或
快速安装
命令(在我编写的sbt插件中定义)中运行包
任务时,我试图暂时跳过编译任务。通过将skip
设置置于compile
任务上,我可以跳过所有编译,但这会导致跳过所有compile
任务:
object MyPlugin extends Plugin {
override lazy val settings = Seq(
(skip in compile) := true
)
...
}
我只需要在运行快速安装
命令时跳过编译
。是否有方法临时修改设置,或仅将其范围设置为“快速安装”命令
我尝试了设置转换(基于),该转换应将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))
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
}
}
我不相信这是最可靠的解决方案,但它似乎满足了我的需要
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
}
}
很好,你当然可以接受
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
}
}