问题描述
我有一个简短的 Bash 脚本,它对我的 Scaladoc 注释进行查找和替换,以便生成指向第三方库的外部文档的链接.我希望每次使用 doc
任务生成 Scaladocs 时都运行此脚本.
I have a short Bash script that does a find-and-replace on my Scaladoc comments in order to generate links to external documentation of a third-party library. I would like this script to run every time I generate Scaladocs using the doc
task.
我怎样才能做到这一点?
How can I achieve this?
推荐答案
其实很简单.首先,我检查了 doc 看它是什么(inspect doc
on the sbt prompt),注意到它是一个任务,然后继续在 build.sbt
:
It's actually pretty easy. First, I inspected doc to see what it was (inspect doc
on the sbt prompt), noticed it was a task, and proceeded with declaring a dependency on itself on build.sbt
:
doc in Compile <<= doc in Compile map { (file) =>
Seq("bash", "-c", "ls >tmp.log").! // CWD is sbt's current dir
file
}
我用来执行bash
的那个东西和scala.sys.process
是同一个库,所以你可以查一下Scaladoc .这是在 SBT 0.12.2 上测试的,我认为在 SBT 0.11.x 或 0.10.x 上可能会有细微差别.
That thing I used to execute bash
is the same library as scala.sys.process
, so you can look up Scaladoc for that. This was tested on SBT 0.12.2, and I think there might be a small difference on SBT 0.11.x or 0.10.x.
这篇关于使用 doc 任务生成 scaladoc 后如何运行 bash 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!