【问题标题】:My First Akka project in IntelliJ from scratch. Compile dependency error.我在 IntelliJ 中从头开始的第一个 Akka 项目。编译依赖错误。
【发布时间】:2016-07-24 05:47:57
【问题描述】:

我时不时地从头开始,以确保我知道设置项目的所有复杂细节是什么。我有一个像下面这样的简单应用程序,但我遇到了一些似乎并没有指向任何地方的依赖问题。我正在使用 scala 版本 2.11。

我的 SBT:

name := "Helios"

version := "1.0"

scalaVersion := "2.11.8"

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

libraryDependencies ++= Seq(
  "com.typesafe.akka" % "akka-actor" % "2.0.2",
  "com.typesafe.akka" % "akka-slf4j" % "2.0.5")

我的示例类

import com.echostar.ese.helios.core.Asset
import akka.actor._

class NSPSG extends Actor {

  def receive = {
    case a: Asset => {
      println(s"NSPSG Received asset: ${a}")
    }
    case _ => println("Unexpected message received")
  }
}

(资产类只是一个案例类,里面有id和title。)

错误信息

C:\PROJECTS\active\Helios>sbt compile
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading global plugins from C:\Users\dana.murad\.sbt\0.13\plugins
[info] Loading project definition from C:\PROJECTS\active\Helios\project
[info] Set current project to Helios (in build file:/C:/PROJECTS/active/Helios/)
[info] Updating {file:/C:/PROJECTS/active/Helios/}helios...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 3 Scala sources to C:\PROJECTS\active\Helios\target\scala-2.11\classes...
[error] missing or invalid dependency detected while loading class file 'package.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'package.class' was compiled against an incompatible version of scala.
[error] missing or invalid dependency detected while loading class file 'Actor.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'Actor.class' was compiled against an incompatible version of scala.
[error] C:\PROJECTS\active\Helios\src\main\scala\com\echostar\ese\helios\workers\NSPSG.scala:9: illegal inheritance;
[error]  self-type com.echostar.ese.helios.workers.NSPSG does not conform to akka.actor.Actor's selftype akka.actor.Actor
[error] class NSPSG extends Actor {
[error]                     ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 3 s, completed Apr 4, 2016 9:19:45 AM

我的主要应用程序现在只是一个 println。它甚至不叫这个演员。

我是否在 scala 2.11 中使用了错误版本的 akka? -Ylog-classpath 没有帮助

【问题讨论】:

  • 您使用 2.0.2 而不是 2.4.3(当前稳定版)是否有原因?
  • 实验,我尝试使用2.4.0。但我解决了。出于某种原因,它现在可以工作了。我将在下面的回答中澄清......

标签: scala compilation dependencies sbt akka


【解决方案1】:

不知道是什么修复了它,但这里列出了我所做的事情并且项目现在可以编译。

  1. 将 akka 依赖行更改为此(添加了双百分比并将版本更改回 2.4)

    libraryDependencies ++= Seq(
      "com.typesafe.akka" %% "akka-actor" % "2.4.0"
    )
    
  2. 删除了我的运行配置并重新添加。 (我认为 main 的路径显示为红色(无效),因此重做它有助于解决它。我更改了我的包名称,但我认为 intelliJ 在 build-conf 中没有很好地选择重命名)

  3. 从 IntelliJ 菜单(Scala 中的 Akka Main)启动了另一个测试项目,下载所有依赖项需要一些时间。所以也许我的项目需要这些并且没有下载它们?

  4. 删除了注释掉的行(去掉了分号)。我认为这除了完全公开之外没有任何作用,从技术上讲,即使我的演员定义完全相同,我也确实接触了代码。

【讨论】:

  • 你在 build.sbt 中打错了:应该是 "com.typesafe.akka" %% "akka-actor"。不是“com.typesafe.akka”%“akka-actor”。 "%%" 自动将 scala 版本后缀添加到依赖项工件名称。
猜你喜欢
  • 1970-01-01
  • 2017-04-16
  • 1970-01-01
  • 1970-01-01
  • 2019-08-23
  • 2015-01-18
  • 2017-03-30
  • 1970-01-01
  • 2012-07-16
相关资源
最近更新 更多