IntelliJ Bug: Scala 145, Error:scalac: Scala compiler JARs not found
Asked Answered
M

11

37

I try to compile a simple object in IntelliJ:

object Test02 {
    def main(args: Array[String]) {
         println("Hello World"); 
    }
}

I got this message:

Error:scalac: Scala compiler JARs not found (module 'scala02'): 
E:\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.11.8.jar, 
E:\.ivy2\cache\org.scala-lang\scala-compiler\jars\scala-compiler-2.11.8.jar,
E:\.ivy2\cache\org.scala-lang\scala-reflect\jars\scala-reflect-2.11.8.jar

I checked the Project Structure and checked the modules. Modules are located here:

C:/Users/asus1/.ivy2/cache/org.scala-lang/scala-compiler/jars/scala-compiler-2.11.8.jar

How Can I change E: to C:/Users/asus1/ ?
Do I need to move all to E: ?

How people manage when the project and the jar are in different location ?

It seems a big bug of IntellJ ...?

Madel answered 31/3, 2016 at 18:45 Comment(0)
M
5

SOLVED as Follow:

In project settings, you need to manually add:

  1. JDK Folder
  2. Module and dependencies to JDK AND Scala JAR

  3. In library, Add MANUALLY the JAR of Scala (IntelliJ does not add those JAR. it creates compile issues).

  4. in Global library, check the JAR of scala are same.

There is an option to see the DEBUG in verbose mode:

https://intellij-support.jetbrains.com/hc/articles/207241085

This is very useful.

Madel answered 3/4, 2016 at 19:54 Comment(1)
Steps are not clear enough to follow with any confidenceHotchpotch
X
55

Please goto File > Settings (Ctrl+Alt+S, Windows)/Preferences (Mac) > Plugin Search for "scala". Uninstall Scala plugin.. Restart IDE. Reinstall it. Restart IDE and install the plugin. Everything works OK

Xylography answered 3/6, 2016 at 7:44 Comment(4)
Im sure its not advisable to install Scala plugin when configuring IntelliJ after installation.Xylography
upvoting this, this was the only thing that fixed it for me.Heathenize
I have to agree. Nothing works until I reinstall the Scala plugin after IntelliJ version upgrade :(Raseta
Yes, this works. In my case, I had scala 2.12.1 and I wasn't able to use it on my home notebook. Ok. So I reinstalled the plugin and also, I had to download the Scala SDK 2.12.3. IntelliJ alerted that I needed to setup a new Scala SDK. After the download, I had the option to choose between Scala 2.12.3 and 2.11.4, the previous default. After all this updates, I had to refresh the project (opening build.sbt).Overalls
E
13

In the more recent versions of IntelliJ (2020.1.1) at the time of writing this, I was able to solve this problem by removing the Scala SDK configured in the Global Libraries section in IntelliJ and hitting File > Invalid Caches / Restart.

I'm not sure why this solved the issue, perhaps recent versions of the IDE now have automatic detection of Scala compiler JAR files from Maven (which I'm using to build my project).

Erkan answered 3/6, 2020 at 14:29 Comment(2)
This worked for me, but I had to clear the Scala SDK and Invalidate the cache and restart and then first-thing run IntelliJ's build before doing any maven operations. Now it works.Earache
This worked for me as well. In Intellij 2023.1, you can find Invalidate Cache under File > Invalidate CacheReproduce
P
7

If your project is Gradle-based, one possibility is that the project is looking for Scala libraries in the .m2 cache that don't exist. To confirm, open "Project Structure...", go to "Libraries", and examine the list for "Gradle: org.scala-lang:..." that contain errors related to missing files.

If this is the issue, simply re-import the project from scratch.

Powys answered 18/5, 2018 at 16:41 Comment(1)
removing the library + re-importing gradle project helped me to solve the issueAmiamiable
M
5

SOLVED as Follow:

In project settings, you need to manually add:

  1. JDK Folder
  2. Module and dependencies to JDK AND Scala JAR

  3. In library, Add MANUALLY the JAR of Scala (IntelliJ does not add those JAR. it creates compile issues).

  4. in Global library, check the JAR of scala are same.

There is an option to see the DEBUG in verbose mode:

https://intellij-support.jetbrains.com/hc/articles/207241085

This is very useful.

Madel answered 3/4, 2016 at 19:54 Comment(1)
Steps are not clear enough to follow with any confidenceHotchpotch
M
4

https://www.jetbrains.com/help/idea/invalidate-caches.html

IntelliJ IDEA caches a great number of files, therefore the system cache may become overloaded. Sometimes the caches will never be needed again, for example, if you work with frequent short-term projects.

When you invalidate the cache, IntelliJ IDEA rebuilds all projects ever run in the current version of the IDE.

Clear the system cache 1.From the main menu, select File | Invalidate Caches / Restart.

2.In the Invalidate Caches dialog, select an action. You can invalidate the caches and restart the IDE or just restart the IDE.

This worked for me.

Mister answered 10/3, 2021 at 10:32 Comment(0)
P
2

Open File -> Project Structure

Go to Libraries under Project Settings

Click on the minus button on the erroring Scala library

Open an existing Scala class in IntelliJ and you will see the prompt to set up Scala SDK and click on that

Pisa answered 10/9, 2020 at 7:56 Comment(0)
L
2

I was having the same problem, and the solution posted from IntelliJ Developer solved the problem.

Solution:

IntelliJ IDEA 2023.2.5 (Community Edition) Go to File | Settings | Build, Execution, Deployment Under Compiler, click on Scala Compiler Look for ' Incrementality type:' and select IDEA. Apply and close .

Lucielucien answered 11/11, 2023 at 22:41 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Pecker
H
1

This could be the issue : You may have multiple maven projects linked/imported in single IntelliJ IDE window and those maven projects are using different Scala compiler versions.

First you will get multiple compiler versions detected issue, then to fix this issue if may have deleted some compiler version folder/jars from .m2 repo.

Solution : Go to maven view/tab --> Unlink maven projects from IntelliJ IDE which are using different versions of Scala , keep only projects which are using same version of Scala

Hacking answered 5/10, 2022 at 22:51 Comment(1)
This was my issue!Eadith
R
0

For me, the following solution worked:

Go to Project Settings > Modules > Dependencies, select the Scala SDK, Edit, and correct the path of the Scala JARs:

enter image description here

Rhino answered 20/4, 2021 at 14:41 Comment(0)
L
0

Update @Oct 2021: This error means plugin needed an update and was solved by : goto File > Settings (Ctrl+Alt+S, Windows)/Preferences (Mac) > Plugin Search for "scala". Update.

Lotty answered 19/10, 2021 at 5:21 Comment(0)
W
-1

In IntelliJ, ensure that the external libraries are present. If already present, open library settings and check the path to the jars is not in red. If in red, correct the path to the jars

Wide answered 13/4, 2020 at 22:28 Comment(1)
Hi, welcome to the club. Please explain your answerMiscellaneous

© 2022 - 2024 — McMap. All rights reserved.