Skip to content

Instantly share code, notes, and snippets.

@BowlingX
Created March 18, 2012 15:30
Show Gist options
  • Save BowlingX/2075392 to your computer and use it in GitHub Desktop.
Save BowlingX/2075392 to your computer and use it in GitHub Desktop.
How to run code from yourLibrary in sbt with a task
/*File Runner:scala*/
package com.myCompany
object Runner extends App {
val myArgument = args(0)
/*Do whatever you want :)*/
}
/*File Build.scala: */
val myTask = TaskKey[Unit]("my-task", "Runs a Task")
def read(text:String, default:String) = {
SimpleReader.readLine(text format default) match {
case Some(s) if s.nonEmpty => s
case _ => default
}
}
val task = myTask <<= (fullClasspath in Runtime, scalaInstance, streams, taskTemporaryDirectory) map { (cp, si, stream, tmp) =>
val readParam = read("Param: [%s] ", "defaultValue")
toError (new Run(si, false, tmp).run("com.myCompany.Runner", cp.files, Seq(readParam), stream.log))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment