无法使用spray-json依赖项在play项目中工作

时间:2013-09-19 04:59:27

标签: scala spray-json

我花了无数个小时试图将spson json作为依赖项添加到我在scala 2.10上构建的play项目中。

有人可以为项目文件中使用的EXACT魔法咒语提供明确的解释吗?!!!!

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"


    )
}

得到这个:

[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

3 个答案:

答案 0 :(得分:5)

spray-json依赖的格式是:

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

使用%%可确保您获得正在使用的Scala版本的正确版本。

Spray不使用其中一个默认存储库来分发库,因此您还必须指定一个。随后的设置变为:

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

答案 1 :(得分:0)

当我无法在我的项目中使用版本1.3.2中的spray-json依赖时,我遇到了这个问题。 sbt.last.log告诉我:sbt.ResolveException:未解析的依赖:io.spray#spray-json_2.11; 1.3.2:未找到。 事实证明,版本1.3.2中的spray-json工件在http://repo.spray.io存储库中根本不可用。解决方案是使用版本1.3.1。

答案 2 :(得分:0)

我想在独立的测试项目中使用spray json,但是遇到类似的错误。

libraryDependencies += "io.spray" %%  "spray-json" % "1.3.4"
来自https://github.com/spray/spray-json

没有帮助。

https://doc.akka.io/docs/akka-http/current/common/json-support.html添加以下依赖项不会产生任何错误。

libraryDependencies += "com.typesafe.akka" %% "akka-http-spray-json" % "10.1.11"