Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Idea, “Not valid Scala home” error on Windows

Alright, so I have Scala 2.10 installed on my computer, and it works fine in eclipse...

I recently installed IntelliJ Idea to see how good an alternative it was, but apparently it doesn't like my scala installation, it works fine on my macbook, but here it just says "not valid Scala home" despite the fact that it is the correct directory...

Upon creating a project and writing a bit of test code, I try to compile it, and in the debug console it says: "Error: scala: No compiler library set in module untitled1"

so what should I do?

Scala IS installed, but the IDE refuses to recognize its existance

Every time I've tried to use Idea, something always goes wrong

Here's a screenshot of the error:

any help?

Edit: Changing the directory to C:\Program Files (x86)\scala produces the following error:

note that Scala DOES work in Eclipse

Edit2: Going through with the other change, still makes the IDE unable to recognize the compiler

like image 241
Electric Coffee Avatar asked May 19 '13 18:05

Electric Coffee


People also ask

How do I enable Scala in IntelliJ?

To install Scala plugin, press Ctrl+Alt+S , open the Plugins page, browse repositories to locate the Scala plugin, click Install and restart IntelliJ IDEA. Now you can successfully check out from VCS, create, or import Scala projects.

How do I select Scala version in IntelliJ?

Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server.


2 Answers

  1. Path problem. IntelliJ Scala plugin looks for installed distribution by first checking SCALA_HOME environment variable. If it is not set it will then scan folders from PATH environment variable. In the latter case it will ignore the fact that it found binary directory and not actual Scala home (so it will not adjust for added bin at the end of the path). Note that Windows Scala msi installer does not set SCALA_HOME (as it is not needed for Scala to function correctly). So you either set SCALA_HOME environment variable or navigate to that directory (as you did in your second screenshot).

  2. Sources problem. Scala msi installer does not install source jars by default. Again as with SCALA_HOME variable they are not strictly needed. But to avoid manually setting compiler jar and also aesthetically displeasing error in your second screenshot :-) just check "Sources" in setup options screen.

  3. Scaladoc problem. It was not part of the question but for completeness: scala api docs will be installed by msi installer (if you did not uncheck "API Documentation" in setup options). However they are in the "wrong" path from scala plugin perspective: [SCALA_HOME]\doc\api. It wants them instead in: [SCALA_HOME]\doc\scala-devel-docs\api. You can deal with it in variety of ways but I feel the most efficient one is to create a directory junction if you are on Windows 7. Go into elevated command prompt, change directory to [SCALA_HOME]\doc and run mklink /j scala-devel-docs . thereby redirecting scala-devel-docs to parent doc folder. Obviously msi uninstall will not remove it so you will have to clean it up if you ever uninstall scala.

like image 158
Incassator Avatar answered Oct 05 '22 13:10

Incassator


Change the Scala home directory to

C:\Program Files (x86)\scala

since that is the home directory. The bin directory is just one of many directories that belongs to the scala installation.

like image 39
maba Avatar answered Oct 05 '22 13:10

maba