Unable to run custom sbt task from AutoPlugin's command

与世无争的帅哥 提交于 2019-12-07 07:30:33

First of all, I assume you just want to call the tasks from your command, and you don't really care if they are added by modifying state in that command.

If so I'd do it more standard way, as it is done by the AutoPlugins.

import sbt._
import Keys._

object MyPlugin extends AutoPlugin {

  object autoImport {
    val taskA = taskKey[Seq[String]]("Task A")
    val taskB = taskKey[Seq[File]]("Task B")
  }

  import autoImport._

  val cmdConfig = config("cmd")

  override def projectConfigurations = Seq(cmdConfig)

  // this is optional of course, you can also enable plugin manually
  override def trigger = allRequirements

  override def projectSettings = 
    Seq(commands += doStuffCommand) ++
    inConfig(cmdConfig)(Seq(
      taskA := {
        println("TASK A")
        Seq("A", "B")
      },
      taskB := {
        println("TASK B")
        Seq(file("."))
      }
    ))


  lazy val doStuffCommand =
   Command.command("doStuff", Help.more("doStuff", "whatever")) {
     (state: State) =>
     val e = Project.extract(state)
     val (newState, bResult) = e.runTask(taskB in cmdConfig, state)
     newState
   }

}

Besides maybe you don't need a command at all, and just having some tasks calling another tasks would be simpler.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!