Scala Dependency on game environment in pure sbt project
I want to create a "utils" dependency for my game project, but I can't find a way to import the game itself without creating a game project. Is there a maven / ivy dependency for the game that I can paste into the sbt build file?
Basically I need to be able to import play.api.mvc._
in an independent sbt project.
+3
source to share
1 answer
You can use Play like any other jar dependency. Example project using some parts of Play (you have to change the Play and Scala versions to suit your needs):
$ tree . ├── build.sbt └── hello.scala
File build.sbt
:
name := "hello"
version := "1.0"
scalaVersion := "2.10.4"
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play" % "2.3.4")
"com.typesafe.play" %% "play-test" % "2.3.4"
)
AND hello.scala
import play.api._
import play.api.mvc._
import play.api.test._
import play.api.test.Helpers._
class TestController extends Controller {
def index = TODO
}
object Hello {
def main(args: Array[String]) = {
Logger.error("Using Play logger")
val fr: FakeRequest[String] = new FakeRequest(
"GET", "/",
new FakeHeaders(Seq.empty), ""
)
val ctrl = new TestController
// Prints the response body
println(contentAsString(call(ctrl.index, fr)))
println("Done")
}
}
This should give you something like this:
$ sbt run
(...)
14:00:12.335 [run-main-0] ERROR application - Using Play logger
<!DOCTYPE html>
<html>
(...)
<body>
<h1>TODO</h1>
<p id="detail">
Action not implemented yet.
</p>
</body>
</html>
Done
+6
source to share