Basic Scala program gives error on JetBrains/Idea/intelliJ - scala

I'm running scala 2.8.0 SDK & Scala Plugin 1.5.2 (latest version) on IntelliJ 14.1.4 (also latest) with java-7-openjdk
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
This is the error I'm receiving
Is there any settings i might have to change to get this to run?
The program runs as a Scala Script on Idea IntelliJ
I must use scala 2.8.0 only not a later version, i'd be happy to change anything else
`Information:24/7/15 12:01 PM - Compilation completed with 1 error and 7 warnings in 30s 907ms
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
Error compiling sbt component 'compiler-interface-2.8.0.final-51.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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)
Warning:scalac: /tmp/sbt_3f4b2dad/compiler-interface-sources/CompilerInterface.scala:161: error: object creation impossible, since method registerTopLevelSym in trait GlobalCompat of type (sym: this.Symbol)Unit is not defined
Warning:scalac: new Compiler() with RangePositions // unnecessary in 2.11
Warning:scalac: ^
Warning:scalac: /tmp/sbt_3f4b2dad/compiler-interface-sources/CompilerInterface.scala:165: error: class Compiler needs to be abstract, since method registerTopLevelSym in trait GlobalCompat of type (sym: Compiler.this.Symbol)Unit is not defined
Warning:scalac: class Compiler extends CallbackGlobal(command.settings, dreporter, output)
Warning:scalac: ^
Warning:scalac: two errors found

Try with scala 2.11.7 or 2.10.5
http://www.scala-lang.org/download/

Out of curiosity, have you tried to use a different JDK?
Maybe JDK6 Hotspot or even JDK7 Hotspot?
I ask because I have seen errors similar to Error compiling sbt component 'compiler-interface-2.8.0.final-51.0' in the past, and they were usually related to incompatibilities with a library and a JDK version.
I cannot test right now, but I will give a look later and try to reproduce if it is still an issue.

For future travellers also setting up Scala for the first time:
I had similar issues and found changing the "Project Interpreter" to the correct JDK (OpenJDK 11 instead of my previous JDK 8) worked.
See e.g.
https://stackoverflow.com/a/29286865/10447904
Many other SO answers that I stumbled across focused on setting the correct JDK using Settings -> Build -> Scala Compiler Server or on the configuration files, but neither of these worked for me.

Related

Intellij scaladoc exception

I'm using intellij community 2018.3 with scala 2.12.
I try to generate scaladoc of my project (a library) but intellij print me this error:
Exception in thread "main" java.lang.NoSuchMethodError: scala.reflect.io.FileZipArchive.allDirsByDottedName()Lscala/collection/Map;
at scala.tools.nsc.classpath.ZipArchiveFileLookup.findDirEntry(ZipArchiveFileLookup.scala:71)
at scala.tools.nsc.classpath.ZipArchiveFileLookup.list(ZipArchiveFileLookup.scala:53)
at scala.tools.nsc.classpath.ZipArchiveFileLookup.list$(ZipArchiveFileLookup.scala:52)
at scala.tools.nsc.classpath.ZipAndJarClassPathFactory$ZipArchiveClassPath.list(ZipAndJarFileLookupFactory.scala:42)
at scala.tools.nsc.classpath.AggregateClassPath.$anonfun$list$1(AggregateClassPath.scala:76)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:944)
at scala.collection.Iterator.foreach$(Iterator.scala:944)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1432)
at scala.collection.IterableLike.foreach(IterableLike.scala:71)
at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at scala.tools.nsc.classpath.AggregateClassPath.list(AggregateClassPath.scala:74)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:271)
at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:220)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1535)
at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:225)
at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:65)
at scala.tools.nsc.Global.rootMirror(Global.scala:63)
at scala.tools.nsc.Global.rootMirror(Global.scala:36)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1423)
at scala.tools.nsc.Global$Run.<init>(Global.scala:1179)
at scala.tools.nsc.doc.DocFactory.makeUniverse(DocFactory.scala:44)
at scala.tools.nsc.doc.DocFactory.generate$1(DocFactory.scala:124)
at scala.tools.nsc.doc.DocFactory.document(DocFactory.scala:131)
at scala.tools.nsc.ScalaDoc.process(ScalaDoc.scala:41)
at scala.tools.nsc.ScalaDoc$.main(ScalaDoc.scala:92)
at scala.tools.nsc.ScalaDoc.main(ScalaDoc.scala)
Process finished with exit code 1
IDE is update. What can I do?
It could be the following:
Also you are on scala 2.12, scala reflect seems to be on 2.11 or other version.
Add a dependency to scala reflect to your project:
https://mvnrepository.com/artifact/org.scala-lang/scala-reflect/2.12.8

Eclipse - Scala - Play - Macro Expansion error

I have defined play json Read on certain case classes
object AccDataResponse {
implicit val AccDataReads = Json.reads[Account] //compile error here
}
I am getting following warning on line Json.reads[Account] in eclipse ide with scala plugin. Project compile fine from maven command line using mvn install. Eclipse seems to treating it as an compilation error with red underline. It causes scala/eclipse code assist and other functionality to not work properly.
How can I get rid of it or disable it? e.g. Tell Eclipse/ScalaIDE not to treat is as compilation error because it is not.
exception during macro expansion: java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.tl$1()Lscala/collection/immutable/List; at play.api.libs.json.JsMacroImpl$CaseClass$1$$anonfun$play$api$libs$json$JsMacroImpl$CaseClass$$applies$1.apply(JsMacroImpl.scala:329) at play.api.libs.json.JsMacroImpl$CaseClass$1$$anonfun$play$api$libs$json$JsMacroImpl$CaseClass$$applies$1.apply(JsMacroImpl.scala:325) at scala.collection.immutable.List.flatMap(List.scala:335) at play.api.libs.json.JsMacroImpl$CaseClass$1.play$api$libs$json$JsMacroImpl$CaseClass$$applies$lzycompute(JsMacroImpl.scala:325) at play.api.libs.json.JsMacroImpl$CaseClass$1.play$api$libs$json$JsMacroImpl$CaseClass$$applies(JsMacroImpl.scala:318) at play.api.libs.json.JsMacroImpl$CaseClass$1.(JsMacroImpl.scala:349) at play.api.libs.json.JsMacroImpl.macroCaseImpl$1(JsMacroImpl.scala:621) at play.api.libs.json.JsMacroImpl.macroImpl(JsMacroImpl.scala:790) at play.api.libs.json.JsMacroImpl.implicitConfigReadsImpl(JsMacroImpl.scala:38) at sun.reflect.GeneratedMethodAccessor668.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$4(JavaReflectionRuntimes.scala:34) at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers$$Lambda$5234/1495203213.apply(Unknown Source) at scala.tools.nsc.typechecker.Macros.macroExpandWithRuntime(Macros.scala:772)

Specs2 Tests Fail to Run Natively in IntelliJ

Running Specs2 in IntelliJ fails. Running the same tests manually via an SBT task works just fine without any problems.
Message: "Test framework quit unexpectedly"
IntelliJ: v.15.0.5 or 2016.2 EAP (build #IC-162.426.1)
Platform: Scala 2.11.7, SBT 0.13.8, Specs2 2.4.17, Play! 2.3.10
This is a common error response, but it looks like the root cause is different for a lot of other people. I have troubleshoot this issue before and corrected it by adding the following to build.sbt:
fork in Test := false
parallelExecution in Test := false
Now the tests are failing again. I have looked through the revision history of our build.sbt file but I do not notice anything significant that would instigate such a regression and I have no clues.
Upon step-debugging the crash I have found the following root cause:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.specs2.reflect.Classes$class.createInstanceFor(Classes.scala:154)
at org.specs2.reflect.Classes$.createInstanceFor(Classes.scala:207)
at org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:145)
at org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:145)
at scala.Option.map(Option.scala:146)
at org.specs2.reflect.Classes$class.createInstanceOfEither(Classes.scala:145)
at org.specs2.reflect.Classes$.createInstanceOfEither(Classes.scala:207)
at org.specs2.reflect.Classes$class.org$specs2$reflect$Classes$$createInstanceForConstructor(Classes.scala:118)
at org.specs2.reflect.Classes$$anonfun$4.apply(Classes.scala:98)
at org.specs2.reflect.Classes$$anonfun$4.apply(Classes.scala:98)
at scala.collection.immutable.List.map(List.scala:273)
at org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:98)
at org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:207)
at org.specs2.reflect.Classes$class.tryToCreateObject(Classes.scala:70)
at org.specs2.reflect.Classes$.tryToCreateObject(Classes.scala:207)
at org.specs2.specification.SpecificationStructure$.createSpecificationFromClassOrObject(BaseSpecification.scala:126)
at org.specs2.specification.SpecificationStructure$.createSpecificationOption(BaseSpecification.scala:107)
at org.specs2.specification.SpecificationStructure$.createSpecification(BaseSpecification.scala:95)
at org.specs2.runner.ClassRunner.createSpecification(ClassRunner.scala:60)
at org.specs2.runner.ClassRunner.start(ClassRunner.scala:31)
at org.specs2.runner.NotifierRunner.start(NotifierRunner.scala:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSpecs2_old(JavaSpecs2Runner.java:133)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSingleTest(JavaSpecs2Runner.java:204)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:85)
Caused by: java.lang.IncompatibleClassChangeError: Found class scalaz.Tree, but interface was expected
at org.specs2.mutable.SideEffectingCreationPaths$class.$init$(FragmentsBuilder.scala:245)
at org.specs2.mutable.Specification.<init>(Specification.scala:12)
at controllers.VerificationApiSpec.<init>(VerificationApiSpec.scala:26)
... 32 more
scalaz.Tree is a transitive dependency of many other dependencies in my project that request versions including 7.1.1, 7.1.2, 7.1.3, 7.0.6 of scalaz. It's interesting to note that in 7.0.x scalaz.Tree is a trait (interface in Java vernacular) but an abstract class in 7.1.x, so this may constitute the root cause.
Is it possible to resolve this issue given the transitive dependency conflicts with scalaz 7.1.x and 7.0.x which are evidentially incompatible?
Specs2 2.4.17 uses Scalaz 7.1.0. Some other dependency in your build is probably dragging a Scalaz 7.2.x dependency. I suggest that you update your specs2 version to 3.8.4 which will bring a more recent version of Scalaz in scope.

Why do i get a ClassNotFoundException on running a simple scala program on IntelliJ 14+?

I'm unable to figure out what is wrong with this program? I'm using an older verison of scala (2.7) because its compatible with certain libraries i'm using
Here is a simple program i'm attempting to run.
The program runs fine using scalac and scala commands.
However on IntelliJ 14+ -> when i create a new project -> select the compiler (scala 2.7) and try to run the above program i get this error below
object SimpleClass {
def main(args: Array[String]) {
println("This is a simple Class")
}
}
Error output.
Why does intelliJ throw the ClassNotFoundException? I've saved the program as SimpleClass.scala
/usr/lib/jvm/java-7-openjdk-i386/bin/java -Didea.launcher.port=7532 -Didea.launcher.bin.path=/home/tejesh/Downloads/idea-IC-141.1532.4/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-7-openjdk-i386/jre/lib/javazic.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/management-agent.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/compilefontconfig.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/java-atk-wrapper.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/icedtea-sound.jar:/usr/local/share/scala-2.7.3/lib/scala-swing.jar:/usr/local/share/scala-2.7.3/lib/scala-library.jar:/home/tejesh/Downloads/idea-IC-141.1532.4/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain SimpleClass
Exception in thread "main" java.lang.ClassNotFoundException: SimpleClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
I've added the folder containing the SimpleClass as under sources
This is the full program here
Recent Scala for IntelliJ IDEA is based on sbt. Apparently Scala 2.7.3 is not supported any longer in this configuration. If you set up a project, IntelliJ will offer you (when you select "Download" for the SDK) no version older than Scala 2.8.0. If you manually select 2.7.3, the following happens when you try to compile:
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
Error compiling sbt component 'compiler-interface-2.7.3.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
...
The next step is Scala 2.8.2, for which you get:
Error:scalac: Parameter '-nobootcp' is not recognised by Scalac.
It seems the oldest Scala that works with the current IntelliJ is 2.9.0. (You have to use Java 7 and not Java 8 for this!)
The solution would be to downgrade IntelliJ IDEA to an old version that still supports Scala 2.7.3 (perhaps IDEA 11?), or to simply set up the project with Scala 2.9.3, but compile instead manually (or using sbt from the terminal) against 2.7.3.
If you have the source to the library that requires 2.7.3, perhaps the best option is to try to compile the library with contemporary versions of Scala (at least 2.9.0).

Exception Occurs when Running Scala Test from Eclipse

I downloaded the Scala IDE Linux - 64 bit For Scala 2.11.2 and am trying to run a Scala Test. Following is my code.
package ppg.experiment.gameofbusiness.engine
import org.scalatest.FlatSpec
import org.scalatest.Matchers
class DiceSpec extends FlatSpec with Matchers {
"A dice" should "roll a value greater than zero" in {
new Dice().roll > 0
}
it should "roll a value less than six" in {
new Dice().roll < 7
}
}
When I right click and run as Scala Test the following is printed on the console
WARNING: -p has been deprecated and will be reused for a different (but still very cool) purpose in ScalaTest 2.0. Please change all uses of -p to -R.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher$.main(ScalaTestLauncher.scala:58)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher.main(ScalaTestLauncher.scala)
Caused by: java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
at org.scalatest.tools.Runner$.argTooShort$1(Runner.scala:1515)
at org.scalatest.tools.Runner$.parseReporterArgsIntoConfigurations(Runner.scala:1532)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:923)
at org.scalatest.tools.Runner$.main(Runner.scala:860)
at org.scalatest.tools.Runner.main(Runner.scala)
... 6 more
Can someone tell me how to solve this problem?
Check your classpath; in particular check that the version of scalatest you're depending on is compiled for scala 2.11, not 2.10.