【问题标题】:Build and Run Akka with Scala 3+使用 Scala 3+ 构建和运行 Akka
【发布时间】:2022-01-20 06:10:33
【问题描述】:

我正在尝试使用 Akka 和 Scala 3+ 构建和运行一个项目,但遇到很多错误。

我的 build.sbt 看起来像

name := "akka"

version := "0.1"

scalaVersion := "3.1.1-RC1"

// https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor-typed
libraryDependencies += "com.typesafe.akka" %% "akka-actor-typed" % "2.6.17"

还有我的示例代码

import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props

class HelloActor extends Actor {
  def receive = {
    case "hello" => println("hello back at you")
    case _       => println("huh?")
  }
}

object Main extends App {
  val system = ActorSystem("HelloSystem")
  // default Actor constructor
  val helloActor = system.actorOf(Props[HelloActor], name = "helloactor")
  helloActor ! "hello"
  helloActor ! "buenos dias"
}

我在控制台中遇到了很多错误

[error] error while loading package$,
[error] class file akka/actor/package.class is broken, reading aborted with class dotty.tools.tasty.UnpickleException
[error] TASTy signature has wrong version.
[error]  expected: {majorVersion: 28, minorVersion: 1}
[error]  found   : {majorVersion: 28, minorVersion: 2 [unstable release: 1]}
[error] 
[error] This TASTy file was produced by an unstable release.
[error] To read this TASTy file, your tooling must be at the same version.
[error] The TASTy file was produced by Scala 3.1.1-RC1-bin-20211007-c041327-NIGHTLY-git-c041327.
[error] error while loading Actor,
[error] class file akka/actor/Actor.class is broken, reading aborted with class dotty.tools.tasty.UnpickleException
[error] TASTy signature has wrong version.
[error]  expected: {majorVersion: 28, minorVersion: 1}
[error]  found   : {majorVersion: 28, minorVersion: 2 [unstable release: 1]}
[error] 
[error] This TASTy file was produced by an unstable release.
[error] To read this TASTy file, your tooling must be at the same version.
[error] The TASTy file was produced by Scala 3.1.1-RC1-bin-20211007-c041327-NIGHTLY-git-c041327.
[error] -- [E006] Not Found Error: /Users/andreacappelletti/Downloads/akka/src/main/scala/Main.scala:6:25 
[error] 6 |class HelloActor extends Actor {
[error]   |                         ^^^^^
[error]   |                         Not found: type Actor
[error] -- [E081] Type Error: /Users/andreacappelletti/Downloads/akka/src/main/scala/Main.scala:8:4 
[error] 8 |    case "hello" => println("hello back at you")
[error]   |    ^
[error]   |    Missing parameter type
[error]   |
[error]   |    I could not infer the type of the parameter x$1 of expanded function:
[error]   |    x$1 => 
[error]   |      x$1 match 
[error]   |        {
[error]   |          case "hello" => 
[error]   |            println("hello back at you")
[error]   |          case _ => 
[error]   |            println("huh?")
[error]   |        }.
[error] four errors found
[error] four errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 5 s, completed Dec 17, 2021 10:31:28 AM

你认为可以用 Scala 3 + 编译 Akka 吗?

我在他们的官方文档上看到可以做到的

https://doc.akka.io/docs/akka/snapshot/project/scala3.html

此外,Akka Actor 2.6.17 支持 Scala 3

https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor_3/2.6.17

【问题讨论】:

  • 你不应该包括 libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.6.17" 吗? (没有打字)
  • 没有任何变化
  • 因为akka-actor-typed依赖akka-actor,所以技术上没问题。

标签: scala sbt akka scala-3 akka-actor


【解决方案1】:

从您链接到的文档页面:

2.6.17 工件只能用于 Scala 3 的夜间构建(即 3.1.1-RC1-bin-20211007-c041327-NIGHTLY)

即将发布的 2.6.18 版本将支持 Scala 3.1.1-RC1。

scalaVersion 设置为3.1.1-RC1-bin-20211007-c041327-NIGHTLY 就足够了。或者,您可以通过跨版本控制使用 Scala 2.13 工件:

libraryDependencies += ("com.typesafe.akka" %% "akka-actor-typed" % "2.6.17").cross(CrossVersion.for3Use2_13)

【讨论】:

  • 您好,感谢您的提示。如何将 scalaVersion 设置为 3.1.1-RC1-bin-20211007-c041327-NIGHTLY 到 build.sbt 文件中?如果我只是将它分配给变量 scalaVersion = "3.1.1-RC1-bin-20211007-c041327-NIGHTLY" 它不会解决依赖关系
猜你喜欢
  • 2014-04-12
  • 2015-12-22
  • 2014-07-16
  • 1970-01-01
  • 1970-01-01
  • 2012-07-24
  • 2016-11-04
  • 2015-07-14
  • 1970-01-01
相关资源
最近更新 更多