Home > Software engineering >  java.lang.NoSuchMethodError: 'void akka.actor.ExtensionId.$init$(akka.actor.ExtensionId)'
java.lang.NoSuchMethodError: 'void akka.actor.ExtensionId.$init$(akka.actor.ExtensionId)'

Time:04-25

I am simply trying to implement a little sample REST endpoint in a scala project using akka. The code looks as follows

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import scala.io.StdIn

import scala.concurrent.ExecutionContextExecutor


object ViewAPI :
  @main def run(): Unit = {
    implicit val system = ActorSystem(Behaviors.empty, "my-system")
    implicit val executionContext = system.executionContext
    val route =
      path("hello") {
        get {
          complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
        }
      }
    val bindingFuture = Http().newServerAt("localhost", 9001).bind(route)

  }

My sbt-file looks as follows:

libraryDependencies  = ("com.typesafe.akka" %% "akka-http" % "10.2.9").cross(CrossVersion.for3Use2_13)

libraryDependencies  = "com.typesafe.akka" %% "akka-actor-typed" % "2.6.19"

libraryDependencies  = "com.typesafe.akka" %% "akka-stream" % "2.6.19"

libraryDependencies  = "org.scalactic" %% "scalactic" % "3.2.11"

libraryDependencies  = "org.scalatest" %% "scalatest" % "3.2.12-RC1" % "test"

libraryDependencies  = "org.scala-lang.modules" %% "scala-swing" % "3.0.0"

libraryDependencies  = "com.google.inject" % "guice" % "4.2.3"

libraryDependencies  = ("net.codingwell" %% "scala-guice" % "5.0.2").cross(CrossVersion.for3Use2_13)

libraryDependencies  = "com.typesafe.play" %% "play-json" % "2.10.0-RC5"

libraryDependencies  = "org.scala-lang.modules" %% "scala-xml" % "2.0.1"

resolvers  = Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))(Resolver.ivyStylePatterns)

And these are the libraries in the project

sbt: com.typesafe.akka:akka-actor-typed_3:2.6.19:jar
sbt: com.typesafe.akka:akka-actor_3:2.6.19:jar
sbt: com.typesafe.akka:akka-http-core_2.13:10.2.9:jar
sbt: com.typesafe.akka:akka-http_2.13:10.2.9:jar
sbt: com.typesafe.akka:akka-parsing_2.13:10.2.9:jar
sbt: com.typesafe.akka:akka-protobuf-v3_3:2.6.19:jar
sbt: com.typesafe.akka:akka-slf4j_3:2.6.19:jar
sbt: com.typesafe.akka:akka-stream_3:2.6.19:jar

When trying to execute the above code, the following exception is thrown:

Exception in thread "main" java.lang.NoSuchMethodError: 'void akka.actor.ExtensionId.$init$(akka.actor.ExtensionId)'
    at akka.http.scaladsl.Http$.<clinit>(Http.scala:845)
    at caro.aview.ViewAPI$.run(ViewAPI.scala:23)
    at caro.aview.run.main(ViewAPI.scala:14)

Does anybody have an idea why that is? Any help would be appreciated, thanks!

CodePudding user response:

I also have this problem. The solution was moving all akka libraries back to Scala 2.13 using the CrossVersion.for3Use2_13 option, the same you have used for akka-http. Looks like a bug in akka for scala 3 version.

  • Related