4

I want to use spray.io with scala 2.11.x akka 2.3.x, and I find the following in the Project Info page of spray.io:

spray 1.3.1 is built against Scala 2.10.3 and Akka 2.3.0 as well as Scala 2.11.1 and Akka 2.3.2.

When I use spray-client, I meet some problem and then I find following in the Documentation page of spray.io, that the spray-client is depended on akka 2.10.x:

akka-actor 2.2.x (with ‘provided’ scope, i.e. you need to pull it in yourself)

What does with provided scope mean? How can I use it with other part of the program written in scala 2.11.x akka 2.3.x?

Edit

Following is the simplest use case listed in the documentation page:

import akka.actor.ActorSystem
import scala.concurrent.Future
object main {
  def main(args: Array[String]) {
    import spray.http._
    import spray.client.pipelining._
    implicit val system = ActorSystem()
    import system.dispatcher // execution context for futures
    val pipeline: HttpRequest => Future[HttpResponse] = sendReceive
    val response: Future[HttpResponse] = pipeline(Get("http://spray.io/"))
  }
}

with build.sbt:

scalaVersion := "2.11.1"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.2"
libraryDependencies += "io.spray" % "spray-client" % "1.3.1"

Although this compiles well, but it meets run time error as:

Uncaught error from thread [default-akka.actor.default-dispatcher-2] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[default]
java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcVL$sp
  at ...
宇宙人
  • 1,197
  • 3
  • 10
  • 28

1 Answers1

5

A provided dependency means, spray requires that dependency but expects the developer to provide it in their build configuration. So, you need to add akka-actor in your build configuration.

If you are using sbt, you can add the following line to you dependencies.

    "com.typesafe.akka"     %% "akka-actor"         % 2.3.2,
Ravi Kiran
  • 1,139
  • 6
  • 10
  • 1
    No, it does not work, I have re-edited my question, by adding build.sbt and a self-contained example. It compiles well, but causes runtime error. – 宇宙人 Sep 09 '14 at 13:37
  • 3
    Change `libraryDependencies += "io.spray" % "spray-client" % "1.3.1"` to `libraryDependencies += "io.spray" %% "spray-client" % "1.3.1"`. Double % between io.spray & spray-client. In current sbt, you are mixing akka built with Scala 2.11 and spray built with Scala 2.10. Hence the exception. – Ravi Kiran Sep 09 '14 at 13:42
  • Thank you, it works. but why is it built with scala 2.10, since I have figured out scalaVersion := "2.11.1"? – 宇宙人 Sep 09 '14 at 13:50
  • 1
    When you put a %% you are asking sbt to find a version that is built with the same Scala version as what you have specified. When you put a single %, it picks the default version of spray-client. The spray team decided that the default version should be 2.10. Read http://stackoverflow.com/questions/17461453/build-scala-and-symbols-meaning – Ravi Kiran Sep 09 '14 at 13:53