Running akka in SBT build task: link configuration unexpectedly missing

I am trying to execute a fairly simple HTTP POST request in a task that I wrote for my SBT assembly, and, seeing that SBT does not seem to have helpers for this, I settled on the spray client to complete this task.

In the file project/dependencies.sbtI will put the following:

resolvers += "spray.io repo" at "http://repo.spray.io/"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.2.3",
  "io.spray" % "spray-client" % "1.2.0")

And my task is implemented:

def uploadSite(version: String, siteArchive: File, log: Logger): HttpResponse = {

  def request: HttpRequest = Post(siteUploadUrl,
    MultipartFormData(Map(
    // abridged
    ))

  implicit val system = ActorSystem() // <-- Exception HERE!
  try {
    import system.dispatcher

    val future: Future[HttpResponse] = pipelining.sendReceive(request)

    Await.result(future, 1 minute)
  }
  finally system.shutdown()
}

The task fails when I run it with the following exception:

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:115)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:138)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:150)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:155)
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:197)
    at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:136)
    at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:470)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:111)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:93)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:82)
    at MyIO$.uploadSite(MyIO.scala:65)

My main analysis is that the file reference.confthat can be found in akka-actor_2.10-2.2.3.jaris not readable, for some reason it eludes me and may have something to do with how SBT manages its classpath to run the build.

: SBT 0.13.0 ( Scala 2.10 ), , akka-actor reference.conf, . , , , (reload plugins then show runtime:fullClasspath in sbt), .

- , , , akka SBT.

, , "akka". - ?

+4
1

, , (, sbt) , , , .

build:

val cl = ??? // Some mechanism of getting Akka classpath with your classes too
val old = Thread.currentThread.getContextClassLoader
Thread.currentThread.setContextClassLoader(cl)
try doSomethingWithAkka()
finally Thread.currentThread.setContextClassLoader(old)

( OP), , :

Akka ( 2.0) , ActorSystem ( ), ( ) :

  • Thread.currentThread.getContextClassLoader
  • getClassLoader
  • ActorSystem.getClass.getClassLoader

, .

, val cl = getClass.getClassLoader ( ), , . 1 , 2.

, ActorSystem, ActorSystem("someName", ConfigFactory.load(cl), cl) , ( - , , )

TL; DR

val system = ActorSystem()

val cl = getClass.getClassLoader
val system = ActorSystem("mySystem", ConfigFactory.load(cl), cl)
+4

All Articles