我在让 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
命令。任何帮助将非常感激!