如何将 bash 脚本作为 sbt 任务执行? [英] How to execute a bash script as sbt task?

查看:30
本文介绍了如何将 bash 脚本作为 sbt 任务执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 Java Play 2.3 应用程序自动构建文档.目前,我使用 Makefile 从 *.dot 文件生成图像并将 Markdown 源合并到 Html/PDF 中:

I want to automatically build documentation for my Java Play 2.3 application. At the moment, I use a Makefile to generate images from *.dotfiles and combine Markdown sources together into Html/PDF:

dot diagram1.dot -Tpdf -o diagram1.pdf
dot diagram2.dot -Tpdf -o diagram2.pdf
pandoc doc1.markdown -o doc1.pdf
# ...

现在我想直接从 SBT 运行这些简单的 bash 命令.这样做的最佳方法是什么?

Now I want to run these simple bash commands directly from SBT. What's the best way to do this?

我在 SBT 参考中找到了一些 SBT 文档插件,但没有什么可以运行一个简单的 shell 脚本.

I found some SBT Documentation plugins in the SBT reference, but nothing to run a simple shell script.

推荐答案

您可以在 External Processes,例如

要运行外部命令,请在其后加上感叹号!:

To run an external command, follow it with an exclamation mark !:

 "find project -name *.jar" !

不要忘记使用import scala.sys.process._,这样!就可以解析为String的方法.

Don't forget to use import scala.sys.process._ so ! can be resolved as a method of String.

在激活器控制台(aka sbt shell)中执行以下操作以执行 yourshell.sh - 注意 eval 命令和周围的引号脚本名称:

Do the following in activator console (aka sbt shell) to execute yourshell.sh - mind the eval command and the quotes around the name of the script:

eval "yourshell.sh" !

要将其作为任务使用,请将以下内容添加到项目的 build.sbt 中:

To have it available as a task add the following to build.sbt of your project:

lazy val execScript = taskKey[Unit]("Execute the shell script")

execScript := {
  "yourshell.sh" !
}

这篇关于如何将 bash 脚本作为 sbt 任务执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆