Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use JSON library without installing Play?

In my build.sbt:

lazy val commonSettings = Seq(
  version := "1.0.0",
  scalaVersion := "2.11.6"
)
lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "myapp",
    libraryDependencies ++= Seq(
      "com.typesafe.play" % "play-json_2.11" % "2.3.4",
      "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test",
      "junit" % "junit" % "4.12" % "test"
    )
  )
resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/")

It compiles well. Now in code I use import play.api.libs.json._ but the compiler gives error saying "not found: object play". Obviously I did not install play. Is it possible to use play-json library without installing Play?

like image 741
Stephan Rozinsky Avatar asked Feb 10 '23 09:02

Stephan Rozinsky


1 Answers

Consider this simple sbt project:

build.sbt

libraryDependencies ++= Seq(
  "com.typesafe.play" %% "play-json" % "2.3.4"
)

resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/")

Then you can run:

sbt console
import play.api.libs.json._
Json.parse("{}")
> res0: play.api.libs.json.JsValue = {}

Yes, you can have play-json without Play. If it is not working in your project, try restarting SBT or do clean, reload, update, compile in SBT.

like image 200
Zeimyth Avatar answered Feb 13 '23 22:02

Zeimyth