What's required to have sbt build with Akka?

12,234

Solution 1

You didn't have all right dependencies for your project.

You have add this one "com.typesafe.akka" %% "akka-actor" % "2.0.5". This one is the main dependency with the core modules for akka. Also it's better to add the following ones for your akka project:

"com.typesafe.akka" %% "akka-actor"    % "2.0.5",
"com.typesafe.akka" %% "akka-slf4j"    % "2.0.5",
"com.typesafe.akka" %% "akka-remote"   % "2.0.5",
"com.typesafe.akka" %% "akka-agent"    % "2.0.5", 
"com.typesafe.akka" %% "akka-testkit"  % "2.0.5"% "test"

And to use actors you should import akka.actor._

Updated

Ok, this build file works for me

name := "hello"

version := "1.0"

scalaVersion := "2.10.1"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor"   % "2.2-M3",
  "com.typesafe.akka" %% "akka-slf4j"   % "2.2-M3",
  "com.typesafe.akka" %% "akka-remote"  % "2.2-M3",
  "com.typesafe.akka" %% "akka-agent"   % "2.2-M3",
  "com.typesafe.akka" %% "akka-testkit" % "2.2-M3" % "test"
)

Don't forget to reload and update your project in sbt

Solution 2

Your akka-actor dependency absolutely CAN NOT be a different version than your other dependencies. And any dependencies you add absolutely CAN NOT be reliant on different versions of akka either or you'll have a very messed up dependency tree.

And you may as well use current versions if you're starting out. Coltrane 2.2-M3 is current at time of writing.

You can add some more akka libs as needed... But this is a basic starting point based on a real project that we run in prod:

name := "app"

organization := "com.yourorg"

version := "0.0.1-SNAPSHOT"

scalaVersion := "2.10.1"

scalacOptions ++= Seq("-unchecked", "-deprecation")

resolvers ++= Seq(
    "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)


libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.2-M3",
  "com.typesafe.akka" %% "akka-slf4j" % "2.2-M3",
  "com.typesafe.akka" %% "akka-testkit" % "2.2-M3"
)

Solution 3

UPDATED ON 24.03.2019

To use Akka Actors you need the following dependencies:

For sbt:

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.5.21",
  "com.typesafe.akka" %% "akka-testkit" % "2.5.21" % Test
)

For Gradle:

dependencies {
  compile group: 'com.typesafe.akka', name: 'akka-actor_2.12', version: '2.5.21'
  testCompile group: 'com.typesafe.akka', name: 'akka-testkit_2.12', version: '2.5.21'
}

For Maven:

<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-actor_2.12</artifactId>
  <version>2.5.21</version>
</dependency>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-testkit_2.12</artifactId>
  <version>2.5.21</version>
  <scope>test</scope>
</dependency>

For more Informations and Dependency-Codesnippets regarding Akka Cluster, Akka Streams, Akka Http, Alpakka etc check: https://akka.io/docs/

Share:
12,234
CruncherBigData
Author by

CruncherBigData

Updated on July 31, 2022

Comments

  • CruncherBigData
    CruncherBigData almost 2 years

    I am trying to use scala -akka from sbt.

    My sbt file looks as follows:

    name := "hello"
    
    version := "1.0"
    
    scalaVersion := "2.9.1"
    
    resolvers += "akka" at "http://repo.akka.io/snapshots"
    
    libraryDependencies ++= Seq(
      "com.codahale"      % "simplespec_2.9.0-1" % "0.4.1",
      "com.typesafe.akka" % "akka-stm"           % "2.0-SNAPSHOT" 
    )
    

    my code:

    import akka._
    
    object HelloWorld {
      def main(args: Array[String]) {
        println("Hello, world!")
      }
    }
    

    When I do sbt compile, I get

    ]# **sbt compile**
    [info] Set current project to default-91c48b (in build file:/var/storage1/home/test_user/dev_scala/hello/)
    [info] Compiling 1 Scala source to /var/storage1/home/test_user/dev_scala/hello/target/scala-2.9.2/classes...
    [error] /var/storage1/home/test_user/dev_scala/hello/src/main/scala/hw.scala:3: not found: object akka
    [error] import akka._
    [error]        ^
    [error] one error found
    [error] (compile:compile) Compilation failed
    [error] Total time: 3 s, completed May 22, 2013 8:59:08 PM
    

    Please advice.

    EDIT2: based on comments bellow. here is the new sbt file

    name := "hello"
    version := "1.0"
    scalaVersion := "2.9.1"
    
    resolvers += "akka" at "http://repo.akka.io/snapshots"
    
    libraryDependencies ++= Seq(
    "com.typesafe.akka" %% "akka-actor" % "2.1.4",
      "com.codahale" % "simplespec_2.9.0-1" % "0.4.1",
      "com.typesafe.akka" % "akka-stm" % "2.0-SNAPSHOT" ,
      "com.typesafe.akka" %% "akka-actor"    % "2.2-M3",
    "com.typesafe.akka" %% "akka-slf4j"    % "2.2-M3",
    "com.typesafe.akka" %% "akka-remote"   % "2.2-M3",
    "com.typesafe.akka" %% "akka-testkit"  % "2.2-M3"% "test"
    )
    

    any ideas ?

  • 4lex1v
    4lex1v about 11 years
    @Hector123 i can't even run sbt with your build.sbt there is no such module at "http://repo.akka.io/snapshots". How did you run this build file?
  • 4lex1v
    4lex1v about 11 years
    @Hector123 i've updated dependencies for akka, it works for me
  • CruncherBigData
    CruncherBigData about 11 years
    I changed it to resolvers += "Typesafe Repository" at "repo.typesafe.com/typesafe/releases" per the akka docs
  • 4lex1v
    4lex1v about 11 years
    @Hector123 Which version of Scala and Akka do you need to use?
  • CruncherBigData
    CruncherBigData about 11 years
    scala 2.10.1 and the latest from akka
  • 4lex1v
    4lex1v about 11 years
    @Hector123 I've updated your build, just copy paste this to your build.sbt and type reload and the update in your sbt console
  • JasonG
    JasonG about 11 years
    Old dependencies in original section. Use current versions of akka and scala for new projects (2.10.1 and akka 2.2-M3 at time of writing)