Adding Play JSON Library to sbt
Asked Answered
S

5

46

How can I add the Play JSON library (play.api.libs.json) to my sbt project?

When I added the following to my plugins.sbt file:

addSbtPlugin("play" % "sbt-plugin" % "2.1.0")

I faced this error:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: play#sbt-plugin;2.1.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

I did not find a resolver for this library, otherwise I would've added it and ran sbt update. Note that my resolvers includes http://repo.typesafe.com/typesafe/releases/.

Sinner answered 17/10, 2013 at 19:58 Comment(3)
Kevin, can you change your answer b/c now you can in play 2.2.Backsheesh
Hi Blankman. I think that the below answer handles play 2.2, no?Sinner
I can't edit and change the answer, it seems to be locked.Backsheesh
W
40

Play 2.3 JSON with SBT >= 0.13.5

put into build.sbt:

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

Play 2.1

build.sbt:

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

scalaVersion := "2.10.2"

libraryDependencies += "play" % "play_2.10" % "2.1.0"

Play JSON is in Play 2.1 not an independent artifact.

Was answered 17/10, 2013 at 22:0 Comment(4)
At the time of writing this was true, not it is an independent lib.Was
Doesn't work for me. Using sbt 13.11. It cannot find com.typesafe.play#play-json_2.10;2.3.4. Probably due to me scala version being 2.10.5. I had to add the typesafe repoDace
on Maven Central is this version: search.maven.org/…Was
had to add the resolvers += ... line even for Play 2.3 and SBT > 0.13.5, and reload. Then worked.Denaedenarius
W
78

Play 2.2 is out and can be added separately from rest of Play Framework. in build.sbt:

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

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.2.1"
Woolf answered 9/12, 2013 at 16:20 Comment(4)
Just what I wanted to find - Perfect timing on your answer!Johnson
+1. After updating your build.sbt with @Carolis's answer, remember to reload in sbt.Sinner
@JeroenKransen I can't change the answer, it is locked.Backsheesh
Excellent. But only works with Scala 2.10 (see @Raul's answer for 2.11+ compatibility).Wednesday
W
40

Play 2.3 JSON with SBT >= 0.13.5

put into build.sbt:

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

Play 2.1

build.sbt:

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

scalaVersion := "2.10.2"

libraryDependencies += "play" % "play_2.10" % "2.1.0"

Play JSON is in Play 2.1 not an independent artifact.

Was answered 17/10, 2013 at 22:0 Comment(4)
At the time of writing this was true, not it is an independent lib.Was
Doesn't work for me. Using sbt 13.11. It cannot find com.typesafe.play#play-json_2.10;2.3.4. Probably due to me scala version being 2.10.5. I had to add the typesafe repoDace
on Maven Central is this version: search.maven.org/…Was
had to add the resolvers += ... line even for Play 2.3 and SBT > 0.13.5, and reload. Then worked.Denaedenarius
B
13

This worked for me (scala 2.11)

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

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.0"

Buttercup answered 15/8, 2014 at 14:28 Comment(2)
The only answer thus far that works with Scala 2.11.Wednesday
I didn't need to add the resolvers line. By the way, current version is 2.5.4, not 2.3.0.Spiritualist
D
1

You can use the following to get the Play JSON library:

addSbtPlugin("play" % "play-json" % "2.2-SNAPSHOT")

You may also have to include the following resolver:

"Mandubian repository snapshots" at "https://github.com/mandubian/mandubian-mvn/raw/master/snapshots/"

Here's where I originally got the info: http://mandubian.com/2013/02/21/play-json-stand-alone/

Davon answered 17/10, 2013 at 20:2 Comment(2)
Hmm I got a missing dependency error from adding the 1 liner. Any way to avoid the git link?Sinner
Now available truly standalone as "com.typesafe.play" %% "play-json" % "2.2.0". See comment by Mandubian in that blog post link "since play 2.2, you don't need my repo anymore"Pirri
R
1

One could check the Getting Started section of the GitHub repository and add the following to the build.sbt file:

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.0-M1"
Rajasthani answered 25/5, 2017 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.