Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's required to have sbt build with Akka?

Tags:

scala

akka

sbt

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 ?

like image 899
CruncherBigData Avatar asked May 22 '13 21:05

CruncherBigData


2 Answers

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

like image 78
4lex1v Avatar answered Sep 30 '22 13:09

4lex1v


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"
)
like image 40
JasonG Avatar answered Sep 30 '22 15:09

JasonG