Scala 编译出错 missing or invalid dependency while loading class

发布于 2022-09-01 05:06:36 字数 4896 浏览 10 评论 0

使用环境:

  1. windows7
  2. idea 14

软件版本:

  1. Scala 2.11.5
  2. Akka 2.0

其中,配置build.sbt的内容如下:

name := "duqi"

version := "1.0"

scalaVersion := "2.11.5"

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

libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0"

测试代码:

import akka.actor.ActorSystem

object ScalaTest{
  def main(args: Array[String]) {
    val system = ActorSystem()
    println("Hello")
  }
}

错误提示:

  1. Error:scalac: missing or invalid dependency detected while loading class file 'package.class'.
    Could not access type ScalaObject in package scala,
    because it (or its dependencies) are missing. Check your build definition for
    missing or conflicting dependencies. (Re-run with -Ylog-classpath to see the problematic classpath.)
    A full rebuild may help if 'package.class' was compiled against an incompatible version of scala.
  2. Error:scalac: missing or invalid dependency detected while loading class file 'ActorSystem.class'.
    Could not access type ScalaObject in package scala,
    because it (or its dependencies) are missing. Check your build definition for
    missing or conflicting dependencies. (Re-run with -Ylog-classpath to see the problematic classpath.)
    A full rebuild may help if 'ActorSystem.class' was compiled against an incompatible version of scala.

原因猜想:

可能是scala和akka的版本不匹配造成的?
关于这个猜想,我已经试过了,将build.sbt的内容换为:

name := "duqi"

version := "1.0"

scalaVersion := "2.9.1"

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

libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0"

但是发现原来的错误没有了,出现下面这一个错误:

Error:scalac: Error:     org.jetbrains.jps.incremental.scala.remote.ServerException
Error compiling sbt component 'compiler-interface-2.9.1.final-52.0'

at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:145)

at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)

at sbt.IO$.withTemporaryDirectory(IO.scala:285)

at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)

at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:139)

at sbt.IO$.withTemporaryDirectory(IO.scala:285)

at sbt.compiler.AnalyzingCompiler$.compileSources(AnalyzingCompiler.scala:139)

at sbt.compiler.IC$.compileInterfaceJar(IncrementalCompiler.scala:33)

at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$.org$jetbrains$jps$incremental$scala$local$CompilerFactoryImpl$$getOrCompileInterfaceJar(CompilerFactoryImpl.scala:87)

at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:44)

at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:43)

at scala.Option.map(Option.scala:145)

at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.getScalac(CompilerFactoryImpl.scala:43)

at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.createCompiler(CompilerFactoryImpl.scala:22)

at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:24)

at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:24)

at org.jetbrains.jps.incremental.scala.local.Cache$$anonfun$getOrUpdate$2.apply(Cache.scala:20)

at scala.Option.getOrElse(Option.scala:120)

at org.jetbrains.jps.incremental.scala.local.Cache.getOrUpdate(Cache.scala:19)

at org.jetbrains.jps.incremental.scala.local.CachingFactory.createCompiler(CachingFactory.scala:23)

at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:22)

at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:62)

at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:20)

at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)

请有了解的同学帮我看看~

参考资料:

  1. akka入门指南
  2. Scala Tour

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城已无爱 2022-09-08 05:06:36

akka 2.0 是两年前的版本,用scala 2.11.5的话 需要akka 2.3.9
Akka Documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文