Question

I have spent countless hours trying to get spray json to be included as a dependency in my play project built on scala 2.10.

Can someone provide definitive explanation for the EXACT magical incantions to use in the project files for this thing?!!!!

Build.scala:

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {
    val appName         = "linscot"
    val appVersion      = "1.0"

    val appDependencies = Seq(
      jdbc,
      anorm,
      "mysql" % "mysql-connector-java" % "5.1.18",
      "com.cloudphysics" % "jerkson_2.10" % "0.6.3",

      //"cc.spray.json" % "spray-json_2.9.1" %"1.0.1"
      "io.spray" %  "spray-json_2.10.1" % "1.2.5"
    )


    val main = play.Project(appName, appVersion, appDependencies).settings(   
      // Add your own project settings here   

        //libraryDependencies += "io.spray" %%  "spray-json" % "1.2.5"


    )
}

getting this:

[info] Updating {file:/Users/Joel/Projects/linscot-server/}linscot...
[warn]  module not found: io.spray#spray-json_2.10.1;1.2.5
[warn] ==== local: tried
[warn]   /Users/Joel/.ivy2/local/io.spray/spray-json_2.10.1/1.2.5/ivys/ivy.xml
[warn] ==== Typesafe Releases Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/io/spray/spray-json_2.10.1/1.2.5/spray-json_2.10.1-1.2.5.pom
[warn] ==== Typesafe Snapshots Repository: tried
[warn]   http://repo.typesafe.com/typesafe/snapshots/io/spray/spray-json_2.10.1/1.2.5/spray-json_2.10.1-1.2.5.pom
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/io/spray/spray-json_2.10.1/1.2.5/spray-json_2.10.1-1.2.5.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]     ::          UNRESOLVED DEPENDENCIES         ::
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
[warn]     :: io.spray#spray-json_2.10.1;1.2.5: not found
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
[error] (*:update) sbt.ResolveException: unresolved dependency: io.spray#spray-json_2.10.1;1.2.5: not found
[warn] some of the dependencies were not recompiled properly, so classloader is not avaialable
[info] Updating {file:/Users/Joel/Projects/linscot-server/}linscot...
[warn]  module not found: io.spray#spray-json_2.10.1;1.2.5
[warn] ==== local: tried
[warn]   /Users/Joel/.ivy2/local/io.spray/spray-json_2.10.1/1.2.5/ivys/ivy.xml
[warn] ==== Typesafe Releases Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/io/spray/spray-json_2.10.1/1.2.5/spray-json_2.10.1-1.2.5.pom
[warn] ==== Typesafe Snapshots Repository: tried
[warn]   http://repo.typesafe.com/typesafe/snapshots/io/spray/spray-json_2.10.1/1.2.5/spray-json_2.10.1-1.2.5.pom
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/io/spray/spray-json_2.10.1/1.2.5/spray-json_2.10.1-1.2.5.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]     ::          UNRESOLVED DEPENDENCIES         ::
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
[warn]     :: io.spray#spray-json_2.10.1;1.2.5: not found
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
[error] (*:update) sbt.ResolveException: unresolved dependency: io.spray#spray-json_2.10.1;1.2.5: not found
Was it helpful?

Solution

The format for spray-json dependency is:

"io.spray" %%  "spray-json" % "1.2.5"

Using %% ensures you get the right version for the version of Scala you are using.

Spray doesn't use one of the default repositories for distribution of the library, so you also have to specify that one. The settings with that then become:

val main = play.Project(appName, appVersion, appDependencies).settings(   
    resolvers += "spray" at "http://repo.spray.io/",
    libraryDependencies += "io.spray" %%  "spray-json" % "1.2.5"
)

OTHER TIPS

I came across this question when i couldn't get the spray-json dependency in version 1.3.2 working in my project. The sbt.last.log was telling me: sbt.ResolveException: unresolved dependency: io.spray#spray-json_2.11;1.3.2: not found. It turned out that spray-json artifact in version 1.3.2 is simply not available in http://repo.spray.io repository. The solution is to use version 1.3.1 instead.

I wanted to use spray json in standalone test project, but was facing similar error.

libraryDependencies += "io.spray" %%  "spray-json" % "1.3.4"

from https://github.com/spray/spray-json was not helpful.

Adding below dependency from https://doc.akka.io/docs/akka-http/current/common/json-support.html didn't give any error.

libraryDependencies += "com.typesafe.akka" %% "akka-http-spray-json" % "10.1.11"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top