Scala版本混淆

时间:2017-01-15 00:35:46

标签: scala intellij-idea sbt fedora

我已经注册了Scala功能编程课程课程并完成了我遇到这个问题的初步设置练习。

当试图编译一个" Hello world"通过Intellij IDEA终端的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:< / p>

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

这是类路径上的版本:

enter image description here

然而,即使在项目sais根目录的终端中尝试简单的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

更新

这是完整的堆栈跟踪(使用&#39; 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.

1 个答案:

答案 0 :(得分:0)

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

然而,&#34;窃听&#34; rpm是0.13.13,我没有使用它我使用0.13.13.1(其中包括修复),所以他们仍然在研究它。因为我不得不继续上课,所以我安装了Ubuntu 16.04而不是我的Fedora 24,其中一切都可以正常运行。