Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a bash script as sbt task?

Tags:

sbt

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 # ... 

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

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

like image 955
Sonson123 Avatar asked Jul 28 '14 13:07

Sonson123


People also ask

How do I run a program from the terminal in bash?

In order to run a Bash script on your system, you have to use the “bash” command and specify the script name that you want to execute, with optional arguments. Alternatively, you can use “sh” if your distribution has the sh utility installed.


1 Answers

You can find some answers in External Processes in the official documentation of sbt, e.g.

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

 "find project -name *.jar" ! 

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

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" ! 

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" ! } 
like image 181
Jacek Laskowski Avatar answered Oct 01 '22 00:10

Jacek Laskowski