2

I'm trying to build and run a project using Akka and Scala 3+ but I encounter a lot of errors.

My build.sbt looks like

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"

And my sample code

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"
}

I got a lot of errors in the console

[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

Do you think that is it possible to compile Akka with Scala 3 + ?

I read on their official documentation that it can be done

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

Moreover, Akka Actor 2.6.17 supports Scala 3

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

user3476509
  • 171
  • 10

1 Answers1

1

From the doc page you linked to:

The 2.6.17 artifacts can be used only with nightly builds of Scala 3 (i.e. 3.1.1-RC1-bin-20211007-c041327-NIGHTLY)

The forthcoming 2.6.18 release will support Scala 3.1.1-RC1.

Setting your scalaVersion to 3.1.1-RC1-bin-20211007-c041327-NIGHTLY should be sufficient. Alternatively, you can use the Scala 2.13 artifacts via cross versioning:

libraryDependencies += ("com.typesafe.akka" %% "akka-actor-typed" % "2.6.17").cross(CrossVersion.for3Use2_13)
Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
  • Hi, thanks for the tip. How can I set the scalaVersion to 3.1.1-RC1-bin-20211007-c041327-NIGHTLY into the build.sbt file ? If I just assign it to the variable scalaVersion = "3.1.1-RC1-bin-20211007-c041327-NIGHTLY" it does not resolve the dependency – user3476509 Dec 17 '21 at 16:44
  • 1
    @user3476509 `resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"` – Dmytro Mitin Sep 28 '22 at 01:27