Skip to content

Instantly share code, notes, and snippets.

@diversit
Created May 25, 2015 11:43
Show Gist options
  • Save diversit/dca340ef161babc35c62 to your computer and use it in GitHub Desktop.
Save diversit/dca340ef161babc35c62 to your computer and use it in GitHub Desktop.
Custom sbt task to run an application many times
// Custom task to run an application many times.
// Add scriptlet into build.sbt
lazy val runMany = inputKey[Unit]("Running the app many times. Provide nr of times. Defaults to 10.")
runMany in Runtime := {
val args: Seq[String] = Def.spaceDelimited("Number of times to run. Default is: 10.").parsed
val times = Try {
args.head.toInt
}.getOrElse(10)
println(s"Running $times times...")
val myMain: Option[String] = (selectMainClass in Runtime).value
val myRunner: ScalaRun = (runner in Runtime).value
val fcp: Seq[Attributed[File]] = (fullClasspath in Runtime).value
myMain match {
case Some(mainclass) =>
println("Warming up...")
for (i <- 1 to times) {
print(i)
myRunner.run(mainclass, Attributed.data(fcp), Seq.empty[String], streams.value.log)
}
println("Done.")
case None =>
println("No main class selected.")
}
println("Done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment