gpt4 book ai didi

sbt - 如何在自定义 sbt 命令中暂时跳过运行编译任务?

转载 作者:行者123 更新时间:2023-12-04 16:12:13 25 4
gpt4 key购买 nike

我试图在运行 package 时暂时跳过编译任务来自 quick-install 内的任务命令(在我正在编写的 sbt 插件中定义)。我可以通过放置 skip 跳过所有编译compile 上的设置任务,但这会导致所有 compile要跳过的任务:

  object MyPlugin extends Plugin {
override lazy val settings = Seq(
(skip in compile) := true
)
...
}

我需要的是只跳过 compile运行我的 quick-install 时命令。有没有办法临时修改设置,或仅将其范围限定为我的快速安装命令?

我尝试了一个设置转换(基于 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
}
}

我不相信这是最强大的解决方案,但它似乎适合我的需要。

最佳答案

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 - 如何在自定义 sbt 命令中暂时跳过运行编译任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com