【问题标题】:Scala versions confusionScala 版本混淆
【发布时间】:2017-01-20 23:02:43
【问题描述】:

我已报名参加 Scala 函数式编程 Coursera 课程,并完成了遇到此问题的初始设置练习。

尝试通过 Intellij IDEA 的终端编译“Hello world”SBT 项目时出现此错误

[error]      while compiling: /home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/src/main/scala/example/ExampleApp.scala
[error]         during phase: typer
[error]      library version: version 2.10.4
[error]     compiler version: version 2.10.4

还有更多内容,但问题的核心在于 - 在 build.sbt 中,scalac 设置为 2.10.4 (and everything 2.10.4 and less is not competible with Java 8),我将其设置为 2.12.1:

name := "example"

version := "1.0"

scalaVersion := "2.12.1"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.1"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"

libraryDependencies ++= Seq(
  "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6",
  "org.scala-lang" % "scala-reflect" % "2.12.1",
  "org.scala-lang" % "scala-library" % "2.12.1"
)

这是类路径上的版本:

但是,即使在项目根目录的终端中尝试简单的 scala -version 我使用的是旧版本:

[vgorcinschi@localhost example]$ scala -version
Scala code runner version 2.10.4 -- Copyright 2002-2013, LAMP/EPFL
[vgorcinschi@localhost example]$ 

我将 Scala 设置为一个新的位置,但这并没有帮助:

[vgorcinschi@localhost ~]$ echo $SCALA_HOME
/usr/local/scala-2.11.8/

我正在开发 Fedora 24。有关如何在我的操作系统上更改 scala、scalac、scalap 位置的任何帮助都会有所帮助,否则我如何确保在项目中使用正确的 scala 版本?

请注意,我尝试使用 this advice 更改 scala 位置,但也没有用:

[vgorcinschi@localhost ~]$ sudo ln -s /usr/bin/scala /usr/local/scala-2.11.8/bin/scala
[sudo] password for vgorcinschi: 
ln: failed to create symbolic link '/usr/local/scala-2.11.8/bin/scala': File exists

更新

这是完整的堆栈跟踪(用 'last compile: compile 调用):

[debug] 
[debug] Initial source changes: 
[debug]         removed:Set()
[debug]         added: Set(/home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/src/main/scala/example/ExampleApp.scala)
[debug]         modified: Set()
[debug] Removed products: Set()
[debug] Modified external sources: Set()
[debug] Modified binary dependencies: Set()
[debug] Initial directly invalidated sources: Set(/home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/src/main/scala/example/ExampleApp.scala)
[debug] 
[debug] Sources indirectly invalidated by:
[debug]         product: Set()
[debug]         binary dep: Set()
[debug]         external source: Set()
[debug] All initially invalidated sources: Set(/home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/src/main/scala/example/ExampleApp.scala)
[debug] Recompiling all 1 sources: invalidated sources (1) exceeded 50.0% of all sources
[info] Compiling 1 Scala source to /home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/target/scala-2.12/classes...
[debug] Getting compiler-interface from component compiler for Scala 2.12.1
[debug] Getting compiler-interface from component compiler for Scala 2.12.1
[debug] Running cached compiler 6bac1d44, interfacing (CompilerInterface) with Scala compiler version 2.10.4
[debug] Calling Scala compiler with arguments  (CompilerInterface):
[debug]         -bootclasspath
[debug]         /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/classes:/home/vgorcinschi/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.1.jar
[debug]         -classpath
[debug]         /home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/target/scala-2.12/classes:/home/vgorcinschi/.ivy2/cache/org.scalactic/scalactic_2.12/bundles/scalactic_2.12-3.0.1.jar:/home/vgorcinschi/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.12.1.jar:/home/vgorcinschi/.ivy2/cache/org.scala-lang.modules/scala-xml_2.12/bundles/scala-xml_2.12-1.0.6.jar
[error] 
[error]      while compiling: /home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/src/main/scala/example/ExampleApp.scala
[error]         during phase: typer
[error]      library version: version 2.10.4
[error]     compiler version: version 2.10.4
[error]   reconstructed args: -bootclasspath /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-5.b16.fc24.x86_64/jre/classes:/home/vgorcinschi/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.1.jar -classpath /home/vgorcinschi/Documents/ideaProjects/CourseraScalaOne/example/target/scala-2.12/classes:/home/vgorcinschi/.ivy2/cache/org.scalactic/scalactic_2.12/bundles/scalactic_2.12-3.0.1.jar:/home/vgorcinschi/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.12.1.jar:/home/vgorcinschi/.ivy2/cache/org.scala-lang.modules/scala-xml_2.12/bundles/scala-xml_2.12-1.0.6.jar
[error] 
[error]   last tree to typer: Literal(Constant(Hello, world!))
[error]               symbol: null
[error]    symbol definition: null
[error]                  tpe: String("Hello, world!")
[error]        symbol owners: 
[error]       context owners: value <local ExampleApp> -> object ExampleApp -> package example
[error] 
[error] == Enclosing template or block ==
[error] 
[error] Template( // val <local ExampleApp>: <notype> in object ExampleApp
[error]   "App" // parents
[error]   ValDef(
[error]     private
[error]     "_"
[error]     <tpt>
[error]     <empty>
[error]   )
[error]   // 2 statements
[error]   DefDef( // def <init>(): example.ExampleApp.type in object ExampleApp
[error]     <method>
[error]     "<init>"
[error]     []
[error]     List(Nil)
[error]     <tpt> // tree.tpe=example.ExampleApp.type
[error]     Block( // tree.tpe=Unit
[error]       Apply( // def <init>(): Object in class Object, tree.tpe=Object
[error]         ExampleApp.super."<init>" // def <init>(): Object in class Object, tree.tpe=()Object
[error]         Nil
[error]       )
[error]       ()
[error]     )
[error]   )
[error]   Apply(
[error]     "println"
[error]     "Hello, world!"
[error]   )
[error] )
[error] 
[error] == Expanded type of tree ==
[error] 
[error] ConstantType(value = Constant(Hello, world!))
[error] 
[error] uncaught exception during compilation: scala.reflect.internal.MissingRequirementError
scala.reflect.internal.MissingRequirementError: class scala.annotation.serializable in compiler mirror not found.
        at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
        at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
        at scala.reflect.internal.Mirrors$RootsBase$$anonfun$getModuleOrClass$3.apply(Mirrors.scala:49)
        at scala.reflect.internal.Mirrors$RootsBase$$anonfun$getModuleOrClass$3.apply(Mirrors.scala:49)
        at scala.reflect.internal.Symbols$Symbol.orElse(Symbols.scala:2229)
        at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)
        at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
        at scala.reflect.internal.Mirrors$RootsBase.getClassByName(Mirrors.scala:99)
        at scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:102)
        at scala.reflect.internal.Mirrors$RootsBase.requiredClass(Mirrors.scala:105)
        at scala.reflect.internal.Definitions$DefinitionsClass.SerializableAttr$lzycompute(Definitions.scala:962)
        at scala.reflect.internal.Definitions$DefinitionsClass.SerializableAttr(Definitions.scala:962)
        at scala.reflect.internal.Symbols$Symbol.isSerializable(Symbols.scala:720)
        at scala.tools.nsc.typechecker.SyntheticMethods$class.needsReadResolve$1(SyntheticMethods.scala:324)
        at scala.tools.nsc.typechecker.SyntheticMethods$class.extras$1(SyntheticMethods.scala:357)
        at scala.tools.nsc.typechecker.SyntheticMethods$class.synthesize$1(SyntheticMethods.scala:367)
        at scala.tools.nsc.typechecker.SyntheticMethods$$anonfun$addSyntheticMethods$2.apply(SyntheticMethods.scala:400)
        at scala.tools.nsc.typechecker.SyntheticMethods$$anonfun$addSyntheticMethods$2.apply(SyntheticMethods.scala:398)
        at scala.reflect.internal.Trees$class.deriveTemplate(Trees.scala:1610)
        at scala.reflect.internal.SymbolTable.deriveTemplate(SymbolTable.scala:13)
        at scala.tools.nsc.typechecker.SyntheticMethods$class.addSyntheticMethods(SyntheticMethods.scala:398)
        at scala.tools.nsc.Global$$anon$1.addSyntheticMethods(Global.scala:493)
        at scala.tools.nsc.typechecker.Typers$Typer.finishMethodSynthesis(Typers.scala:1848)
        at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1810)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5584)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
        at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2928)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
        at scala.collection.immutable.List.loop$1(List.scala:170)
        at scala.collection.immutable.List.mapConserve(List.scala:186)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3032)
        at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5301)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5587)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5704)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:464)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
        at scala.collection.Iterator$class.foreach(Iterator.scala:727)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:91)
        at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1583)
        at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1557)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:1553)
        at scala.tools.nsc.Global$Run.compile(Global.scala:1662)
        at xsbt.CachedCompiler0.run(CompilerInterface.scala:123)
        at xsbt.CachedCompiler0.run(CompilerInterface.scala:99)
        at xsbt.CompilerInterface.run(CompilerInterface.scala:27)
        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:498)
        at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102)
        at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:48)
        at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)
        at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:98)
        at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:98)
        at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:98)
        at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:159)
        at sbt.compiler.AggressiveCompile$$anonfun$3.compileScala$1(AggressiveCompile.scala:97)
        at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:142)
        at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:86)
        at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:38)
        at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:36)
        at sbt.inc.Incremental$.cycle(Incremental.scala:73)
        at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:33)
        at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:32)
        at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:41)
        at sbt.inc.Incremental$.compile(Incremental.scala:32)
        at sbt.inc.IncrementalCompile$.apply(Compile.scala:26)
        at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:150)
        at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:70)
        at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:45)
        at sbt.Compiler$.apply(Compiler.scala:70)
        at sbt.Defaults$.sbt$Defaults$$compileTaskImpl(Defaults.scala:736)
        at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:730)
        at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:730)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
        at sbt.std.Transform$$anon$4.work(System.scala:64)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
        at sbt.Execute.work(Execute.scala:244)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[error] (compile:compile) scala.reflect.internal.MissingRequirementError: class scala.annotation.serializable in compiler mirror not found.

【问题讨论】:

  • 您可以通过sbt 运行所有内容。如果您希望 REPL 使用 scala,请尝试使用 sbt console。这将获取您的构建设置。
  • 它没有选择构建版本 - 完全相同的错误
  • 如果你 cd 到带有 build.sbt 的目录并运行 sbt console 它会给你一个 scala 版本而不是 build.sbt 中指定的版本?
  • 是的,这就是它给我的:-“编译器版本:版本 2.10.4”可能是因为我的 /home/username/ 目录中有 .sbt 和 .ivy2?
  • 我们可以看看你的build.sbt吗?您还使用了错误的命令ls 而不是ln

标签: scala intellij-idea sbt fedora


【解决方案1】:

最后 - 我无法解决它。我向 sbt github 组提出了一个问题,他们将其标记为错误:https://github.com/sbt/sbt/issues/2923

然而,“错误”的 rpm 是 0.13.13,我没有使用它,我使用的是 0.13.13.1(其中包括修复),所以他们仍在研究它。由于我必须继续上课,所以我安装了 Ubuntu 16.04 而不是我的 Fedora 24,在那里一切正常。

【讨论】:

    猜你喜欢
    • 2020-01-31
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    相关资源
    最近更新 更多