Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute runMain from custom task?

Tags:

sbt

I'm using sbt v0.13.5

In my project, I'd like to have an sbt task that can accept some input (a single string), do some work on it and spit back some output (again, a single string). I've created a helper class in my project that does this that I can call from the terminal via sbt runMain (sbt "runMain com.example.utils.ClassName someArgument").

What I'd like is to save myself some typing and have an sbt task that does this. I'd like to just be able to type sbt doThing withStuff and have a taskKey named doThing that calls runMain with the name of the class to run and whatever argument was passed in.

I know how to create tasks but I can't seem to figure out how to call runMain from a custom task definition in my build.sbt. Can anyone point me in the correct direction?

like image 432
mbcrute Avatar asked Oct 07 '14 19:10

mbcrute


1 Answers

TaskKey[Unit]("myTask") := (runMain in Compile).toTask(" com.example.Main arg1 arg2").value

runMain is an InputTask. InputTask has toTask method since 0.13.1.

  • https://github.com/sbt/sbt/commit/9dcb8727d819fb
  • https://github.com/sbt/sbt/blob/v0.13.6/main/settings/src/main/scala/sbt/InputTask.scala#L33
  • http://www.scala-sbt.org/0.13/docs/Input-Tasks.html#Get+a+Task+from+an+InputTask
like image 138
Kenji Yoshida Avatar answered Sep 27 '22 22:09

Kenji Yoshida