【问题标题】:SBT Subprojects do not recognize plugin commandsSBT 子项目无法识别插件命令
【发布时间】:2015-04-22 14:25:41
【问题描述】:

我在让 SBT 子项目识别插件提供的命令时遇到问题。我有以下插件源:

object DemoPlugin extends AutoPlugin {
  override lazy val projectSettings = Seq(commands += demoCommand)

  lazy val demoCommand =
    Command.command("demo") { (state: State) =>
      println("Demo Plugin!")
      state
    }
}

由配置如下的项目使用:

lazy val root = project in file(".")

lazy val sub = (project in file("sub")).
  enablePlugins(DemoPlugin).
  settings(
    //...
  )

该插件当然在project/plugins.sbt 中列出。但是,当我在项目中打开 sbt 时,会看到以下内容:

> sub/commands
[info] List(sbt.SimpleCommand@413d2cd1)
> sub/demo
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: demo (similar: doc)
[error] sub/demo

更陌生,使用consoleProject,我可以看到项目中的命令是DemoPlugin定义的那个!

scala> (commands in sub).eval.map { c => c.getClass.getMethod("name").invoke(c) }
res0: Seq[Object] = List(demo)

我希望能够输入sub/demo,并让它执行demo 命令。任何帮助将不胜感激!

【问题讨论】:

    标签: sbt sbt-plugin


    【解决方案1】:

    命令不是针对每个项目的。它们只适用于顶级项目。

    还建议尝试使用任务,或者如果需要输入您可能想要使用命令的任务。

    如果你真的需要命令,有一种方法可以有一种“持有人”任务,请参阅Can you access a SBT SettingKey inside a Command?的答案

    【讨论】:

      猜你喜欢
      • 2014-12-14
      • 2013-10-29
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 2021-08-21
      相关资源
      最近更新 更多