首页 > 解决方案 > 执行 sbt 命令时可以运行 scala 脚本吗?

问题描述

每当我们使用诸如“sbt compile”或“sbt assembly”之类的 sbt 命令时,我都想运行一个脚本。

有没有办法做到这一点?

标签: scalasbt

解决方案


将步骤附加到任务的完成类似于以下内容:

compile <<= (compile in Compile) map {result =>
  // whatever you want to do after compile here.
  result
}

如果你想定义一个Command运行你的脚本的自定义,那么在你的构建中定义一个命令,类似于

def myCommand = Command.command("myCommand") { state =>
  s"<relative path to script here>" !; state
}

然后,您将添加myCommand到您myCommand想要运行的每个任务。


推荐阅读