Arpit Agarwal
Arpit Agarwal

Reputation: 667

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?

Upvotes: 7

Views: 6758

Answers (4)

Roman Kazanovskyi
Roman Kazanovskyi

Reputation: 3599

in my case i went into Compiler/Scala Compiler settings and deleted additional compiler options (make -transitive)

Upvotes: 0

niktrop
niktrop

Reputation: 576

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.

Upvotes: 4

Pontios
Pontios

Reputation: 2394

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...

Upvotes: 2

erkfel
erkfel

Reputation: 1668

I had similar issue when run Idea under the root user. Idea was not able to find the scala library. I solved the issue by quitting the Idea and run it under my current user.

Upvotes: 0

Related Questions