8

我正在尝试使用来自 sbt 的 scala -akka。

我的 sbt 文件如下所示:

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

我的代码:

import akka._

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

当我这样做时sbt compile,我得到

]# **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

请指教。

EDIT2:基于下面的评论。这是新的 sbt 文件

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

有任何想法吗 ?

4

3 回答 3

12

您的项目没有所有正确的依赖项。

你已经添加了这个"com.typesafe.akka" %% "akka-actor" % "2.0.5"。这是 akka 核心模块的主要依赖项。此外,最好为您的 akka 项目添加以下内容:

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

要使用演员,您应该导入 akka.actor._

更新

好的,这个构建文件对我有用

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

不要忘记reloadupdate你的项目在 sbt

于 2013-05-22T21:28:48.113 回答
1

您的 akka-actor 依赖项绝对不能是与其他依赖项不同的版本。并且您添加的任何依赖项绝对不能依赖于不同版本的akka​​,否则您将拥有一个非常混乱的依赖关系树。

如果您刚开始,您也可以使用当前版本。Coltrane 2.2-M3 在撰写本文时是最新的。

您可以根据需要添加更多 akka 库......但这是基于我们在 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"
)
于 2013-05-24T02:36:08.657 回答
1

更新于 24.03.2019

要使用 Akka Actors,您需要以下依赖项:

对于 sbt:

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

对于 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'
}

对于 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>

有关 Akka Cluster、Akka Streams、Akka Http、Alpakka 等的更多信息和依赖代码片段,请查看:https ://akka.io/docs/

于 2019-03-24T15:42:23.880 回答