Create a gist now

Instantly share code, notes, and snippets.

@jmhofer /Build.scala
Last active Dec 20, 2016

SBT build for Scalatron (see also https://github.com/jmhofer/scalatron-bot.g8)
// copy all jars from Scalatron's distribution (bin directory) into lib/
lazy val botDirectory = settingKey[File]("bot-directory")
lazy val play = taskKey[Int]("Plays a game of Scalatron, returns the exit code upon completion.")
lazy val Versions = new {
lazy val Specs2 = "3.8.6"
}
lazy val root = (project in file(".")).settings(
inThisBuild(Seq(
organization := "de.johoop",
scalaVersion := "2.12.1",
scalacOptions ++= Seq("-encoding", "UTF8", "-deprecation", "-unchecked"),
scalacOptions in Test += "-Yrangepos"
)),
name := "scalatron-bot",
libraryDependencies += "org.specs2" %% "specs2-core" % Versions.Specs2 % Test,
botDirectory := file("bots"),
javaOptions += "-Xmx1g",
play := {
val bots = botDirectory.value
val ucp = (unmanagedClasspath in Compile).value
val botJar = (Keys.`package` in Compile).value
IO createDirectory (bots / name.value)
IO copyFile (botJar, bots / name.value / "ScalatronBot.jar")
Fork.java(
config = ForkOptions(
runJVMOptions = javaOptions.value ++ Seq("-cp", (ucp.files :+ botJar).absString)
),
arguments = Seq("scalatron.main.Main", "-plugins", bots.absolutePath)
)
}
)
@asflierl

instead of manual String formatting in "play" you could do this:

("java" :: javaOptions ::: "-cp" :: Seq(ucp.files.head, botJar).absString :: "scalatron.main.Main" :: "-plugins" :: bots :: Nil) !

or you could use the Fork API:

Fork.java(.....)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment