How to temporarily skip compilation start in user sbt command?

I am trying to temporarily skip the compilation task when starting the package task from the quick-install command (defined in the sbt plugin that I am writing). I can skip all compilations by putting the skip parameter in the compile task, but this will skip all compile tasks:

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

I only need to skip compile when running my quick-install command. Is there a way to temporarily change a setting or include it only in my quick install command?

I tried converting settings (based on https://github.com/harrah/xsbt/wiki/Advanced-Command-Example ), which should replace all instances of skip := false with skip := true , but it doesnโ€™t have which any effect (i.e. compilation still occurs after conversion):

 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) ... } 

Any idea what I am missing and / or the best way to do this?

Edit:

The value of the omissions is a task, therefore an easy fix:

 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 } } 

I'm not sure if this is the most reliable solution, but it works for what I need.

+6
source share
1 answer
 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 } } 

Well of course you can go with that!

0
source

Source: https://habr.com/ru/post/913531/


All Articles