Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij not able to run Scala Code

I have a project that uses both Java and Scala code. When I am trying to run a main function from Scala on Intellij 13.1.4 with Scala Plugin 0.38.441 installed I get the following error

Error:scalac: Error: Scala instance doesn't exist or is invalid: 
    version unknown, library jar: /home/arpit/.m2/repository/org/scala-lang/scala-library/2.11/scala-library-2.11.jar, compiler jar: /home/arpit/.m2/repository/org/scala-lang/scala-compiler/2.11/scala-compiler-2.11.jar
sbt.InvalidScalaInstance: Scala instance doesn't exist or is invalid: 
    version unknown, library jar: /home/arpit/.m2/repository/org/scala-lang/scala-library/2.11/scala-library-2.11.jar, compiler jar: /home/arpit/.m2/repository/org/scala-lang/scala-compiler/2.11/scala-compiler-2.11.jar
    at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:122)
    at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:119)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:32)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:32)
    at scala.Option.getOrElse(Option.scala:120)
    at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:32)
    at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:32)
    at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$.org$jetbrains$jps$incremental$scala$local$CompilerFactoryImpl$$getOrCompileInterfaceJar(CompilerFactoryImpl.scala:79)
    at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:43)
    at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:42)
    at scala.Option.map(Option.scala:145)
    at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.getScalac(CompilerFactoryImpl.scala:42)
    at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.createCompiler(CompilerFactoryImpl.scala:21)
    at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:23)
    at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:23)
    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)

I also checked for compiler settings under Project setting in IntelliJ and for Scala Compiler it says "Nothing to show here in external build mode". Can this be the problem?

like image 730
Arpit Agarwal Avatar asked Jul 30 '14 00:07

Arpit Agarwal


People also ask

Why Scala class is not showing in IntelliJ?

On the Project pane on the left, right-click src and select New => Scala class. If you don't see Scala class, right-click on HelloWorld and click on Add Framework Support…, select Scala and proceed. If you see Error: library is not specified, you can either click download button, or select the library path manually.

How do I open a Scala project in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.


2 Answers

It seems that the compiler cannot read the version of the scala-compiler jar. Maybe it is corrupted. Try to redownload it or to use another version. To set another compiler library go to Project Structure/Facets/Scala facet of your module and select a suitable library.

If it does not work please create a ticket on the bugtracker (with the attached compiler library): http://youtrack.jetbrains.com/issues/SCL

Also you can try to change the type of the incremental compiler in Settings/IDE Settings/Scala

There is nothing wrong with the Compiler/Scala Compiler settings.

like image 69
niktrop Avatar answered Sep 21 '22 20:09

niktrop


I had the same problem, that's what I've done:

(After installing IntelliJ and SBT) I downloaded Scala as well from this website and installed it.

Then I went to File -> Project Structure -> Libraries and I removed the existing library.

Afterwards, I clicked the "+" symbol and "Scala SDK" and found the Scala installation folder (C:\Program Files (x86)\scala\ in my case).

And followed the instructions. Then everything worked fine...

Hope it helps...

like image 25
Pontios Avatar answered Sep 18 '22 20:09

Pontios