How to run bash script after generating scaladoc using doc task?

I have a short Bash script that finds and replaces my Scaladoc comments to generate links to external documentation of a third-party library. I would like this script to be executed every time I generate Scaladocs using the doc task.

How can i achieve this?

+5
source share
2 answers

This is actually pretty easy. First, I checked the document to find out what it was ( inspect doc at the sbt prompt), noticed that it was a task, and continued declaring dependency on myself at build.sbt :

 doc in Compile <<= doc in Compile map { (file) => Seq("bash", "-c", "ls >tmp.log").! // CWD is sbt current dir file } 

What I used to execute bash is the same library as scala.sys.process , so you can search for Scaladoc for this . This has been tested on SBT 0.12.2, and I think there might be a slight difference in SBT 0.11.x or 0.10.x.

+5
source

In sbt 0.13 and recent versions, the use case can also be achieved using macros := and .value (which should be simpler than <<= ):

 doc in Compile := { val f = (doc in Compile).value // execute a shell script if you want with sbt Process API // http://www.scala-sbt.org/0.13/docs/Process.html val ec = (baseDirectory.value / "myBashScript.sh").getAbsolutePath ! val log = streams.value.log log.debug(s"Exit code: $ec") f } 

You may also like the triggeredBy method for tasks as follows:

 lazy val runMyBashScriptTask = taskKey[Unit]("Run myBashScript") runMyBashScriptTask := { val ec = (baseDirectory.value / "myBashScript.sh").getAbsolutePath ! val log = streams.value.log log.debug(s"Exit code: $ec") } runMyBashScriptTask <<= runMyBashScriptTask triggeredBy (doc in Compile) 

myBashScript.sh is assumed to be located in the main project directory, as indicated by setting baseDirectory .

+1
source

All Articles