在子项目范围内运行sbt命令

问题描述 投票:0回答:1

我有一个带有子项目的sbt项目。有两种方法可以在特定的子项目上运行任务:1.sbt proj1/compile2. sbt "project proj1" compile

但是如果我定义一个命令,例如:

def hello = Command.command("hello") { state =>
  println("Hi!")
  state
}

sbt "project prog1" hello运行可以正常工作,但是当我运行sbt prog1/hello时,出现以下错误:

[error] Expected ';'
[error] Expected ':'
[error] Not a valid key: hello (similar: shellPrompt)
[error] proj1/hello
[error]                    ^

是否有这种差异的原因?任何使sbt prog1/hello工作的方法?

scala sbt
1个回答
0
投票

您可以在项目设置中定义自定义任务:

lazy val customTask = taskKey[Unit]("My custom task")
lazy val `proj1` = project
  .settings(
    customTask:= {println("Hello")}
  )

您将可以使用:sbt prog1 / customTask

© www.soinside.com 2019 - 2024. All rights reserved.