【问题标题】:Scala claims I am using different versions of AkkaScala 声称我正在使用不同版本的 Akka
【发布时间】:2018-01-21 12:05:35
【问题描述】:

View repository at this specific commit here

我正在组建一个小型 SBT 项目并学习如何使用 akka 演员。我能够得到一个只使用 akka 的简单示例,但是一旦我使用外部库,事情就会停止工作。我得到了一个非常大的堆栈跟踪

objc[15196]: Class JavaLaunchHelper is implemented in both 
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java (0x10cc6c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10ccf84e0). One of the two will be used. Which one is undefined.
Detected java.lang.NoSuchMethodError error, which MAY be caused by incompatible Akka versions on the classpath. Please note that a given Akka version MUST be the same across all modules of Akka that you are using, e.g. if you use akka-actor [2.5.8 (resolved from current classpath)] all other core Akka modules MUST be of the same version. External projects like Alpakka, Persistence plugins or Akka HTTP etc. have their own version numbers - please make sure you're using a compatible set of libraries.                 
Uncaught error from thread [HelloSystem-akka.actor.default-dispatcher-4]: akka.actor.ActorCell.addFunctionRef(Lscala/Function2;)Lakka/actor/FunctionRef;, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for for ActorSystem[HelloSystem]
java.lang.NoSuchMethodError: akka.actor.ActorCell.addFunctionRef(Lscala/Function2;)Lakka/actor/FunctionRef;

我的依赖项如下所示:

  object v {
    val akka = "2.5.8"
    val scrape = "0.4.0"
  }

  val akka = Seq(
    "com.typesafe.akka" %% "akka-actor" % v.akka,
    "com.typesafe.akka" %% "akka-slf4j" % v.akka
  )

  val scrape = Seq(
    "io.bfil" %% "scalescrape" % v.scrape
  )

  lazy val allDeps =  akka ++ scrape

我正在使用this library,它也使用akka 版本5.8,那么给出了什么?这个冲突版本的 akka actor 是从哪里来的?这是我的build.sbt,其中包括我尝试使用的冲突管理器:

import Dependencies._

name := "sputnik-scraper"

version := "0.1"

scalaVersion := "2.12.4"

conflictManager := ConflictManager.strict

dependencyOverrides += "com.typesafe.akka" %% "akka-actor" % "2.5.8"

lazy val root = (project in file(".")).settings(
  libraryDependencies ++= allDeps
)

编辑:从 main 添加代码。

import akka.actor.{ActorSystem, Props}
import io.bfil.scalescrape.actor.ScrapingActor

object Main extends App {

  val system = ActorSystem("HelloSystem")
  // default Actor constructor
  val helloActor = system.actorOf(Props[ExampleScraper], name = "helloactor")
  helloActor ! "hello"
  helloActor ! "buenos dias"
}


class ExampleScraper extends ScrapingActor {

  private val baseUrl = "https://www.sputnikmusic.com/"

  override def receive: Receive = {
    case _       => grabMainTitle(baseUrl)
  }

  private def grabMainTitle(url: String) =
    scrape {
          get(url) { response =>
            complete(doIt(response))
          }
    }

  private def doIt(response: Any): Unit = {
    println(response)
  }
}

【问题讨论】:

  • 如果可能的话,你能在这里提供演员和主程序
  • 我将代码添加到我的原始帖子中。

标签: scala akka


【解决方案1】:

这很有可能是由于scalescrape 中使用的 Akka-HTTP 版本 10.0.1 与 Akka 2.5 不同步造成的。这是更新的Akka-HTTP 10.0.5 的发行说明:

这是 Akka HTTP 10.0 系列的第五个维护版本。它 主要是为了稳定性,使内部结构与 即将发布的 Akka 2.5 版本。 ...

您可能需要考虑将 Akka-HTTP 依赖项修改为更新版本的 Akka HTTP 10.0。目前最新版本是 10.0.11。

【讨论】:

  • 如果scalescrape 包含有冲突的版本,它将如何工作?现在就试试这个。
  • 它不起作用。这是我的完整回购:github.com/gardncl/scala-sputnik-scraper/tree/…
  • 我认为@chunjef 的回答是:显式 Akka Stream 依赖是解决原始问题的关键,尽管根据这个issue discussion,听起来 Akka-HTTP 10.0 可能永远无法与 Akka 2.5 无缝协作.
【解决方案2】:

来自 Akka HTTP 10.0.x 的兼容性指南(scalescrape 0.4.0 依赖于 Akka HTTP 10.0.1):

Akka HTTP 10.0.x (二进制)与 both Akka 2.4.x 和 Akka 2.5.x 兼容,但是为了促进这一点,构建(以及因此发布的工件)依赖于2.4 系列。根据您构建依赖项的方式,您可能会遇到这样一种情况:您依赖于 2.5 系列中的 akka-actor,而您又依赖于 10.0 系列中的 akka-http,这反过来又会传递地拉入 @ 2.4 版本中的 987654330@ 依赖项打破了所有 Akka 模块必须具有相同版本的二进制兼容性要求,因此 akka-streams 依赖项必须与 akka-actor 的版本相同(因此与 2.5 的确切版本相同系列)。

为了解决这个依赖问题,你必须显式地依赖 akka-streams,并使其与你的 Akka 环境的其余部分相同......

将您的 Akka 依赖项更改为以下内容:

val akka = Seq(
  "com.typesafe.akka" %% "akka-actor" % v.akka,
  "com.typesafe.akka" %% "akka-slf4j" % v.akka,
  "com.typesafe.akka" %% "akka-stream" % v.akka // <-- add this
)

(请注意,Akka HTTP 的当前 10.1.x 分支的 compatibility guidelines 已更改。)

【讨论】:

  • 所以这消除了那个错误,但我得到了另一个类似的错误。这个 repo 是否可能由于其自身的内部冲突而无法使用?这是我在深入研究 scala 冲突时得到的:(抱歉,这是在 pastebin 上,但我这里没有足够的字符)pastebin.com/1SMsBcea
  • [warn] 级别的那些日志消息无需担心:它们表明 Akka 2.4.16 jar 已被逐出以支持版本 2.5.8,这正是您想要的。
猜你喜欢
  • 1970-01-01
  • 2014-01-16
  • 2018-02-06
  • 1970-01-01
  • 1970-01-01
  • 2016-03-05
  • 2017-02-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多