3
votes

I want to create a "utils" dependency for my play project, but I can't seem to find a way to import the play framework itself without creating a play project. Is there a maven/ivy dependency for play that I can put into my sbt build file?

Basically I need to be able to import play.api.mvc._ on an independent sbt project.

1
playframework.com/documentation/2.2.x/Build I am not sure if you need this but check this out - billpcs
@DoomProg That isn't really what I was looking for. I'm looking for the dependency so I can do import play.api._, etc in a clean sbt project, without making it a play project. - Wiz
So this does not work? libraryDependencies ++= Seq("com.typesafe.play" %% "play" % "2.2.2") - billpcs
@Wiz Can you give an example of what you are trying to do (ex some api you want to use)? - Salem
@Salem I basically want to abstract a custom action wrapper into a dependency. So I need to import play.api.mvc._ - Wiz

1 Answers

6
votes

You should be able to use Play as any other jar dependency. A sample project using some parts of Play (you should change the Play and Scala versions to match your needs):

$ tree .
├── build.sbt
└── hello.scala

The build.sbt file:

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", "/",
            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