Error: scala: No 'scala-library*.jar' in Scala compiler library
Asked Answered
H

11

46

Environment: Play 2.3.0/Scala 2.11.1/IntelliJ 13.1

I used Typesafe Activator 1.2.1 to create a new project with Scala 2.11.1. After the project was created, I ran gen-idea. The generated IDEA project fails to compile with the error:

Error: scala: No 'scala-library*.jar' in Scala compiler library in test

Am I doing something wrong? Workaround?

enter image description here

Hydria answered 3/6, 2014 at 16:5 Comment(4)
Apparently a workaround is to create a new IntelliJ scala project, select a scala home directory where 2.11 is installed, check the box to make sure it becomes a "global" library, close this project, go back to the original project, remove the facet, and re-add with the new global library. ARGGHHHH... surely there is a better way. I love the Scala language, but the brittleness of the tools just really makes me mad.Hydria
You don't need to use gen-idea task in IDEA 13.1. SBT support is now built-in. You just need to import SBT project via File/Import project menu item.Honeysucker
Perfect, Vladimir. Even better than gen-idea. You can make this the answer.Hydria
With the default pathway through the New Scala SBT Project pathway, I am receiving this error with IntelliJ 2017.2.5 Scala Plugin 2017.2.11.Chadbourne
H
19

Since IDEA 13 you should use SBT support which is bundled with Scala plugin.

With it there is no need to add third-party SBT plugins and run special commands; just import the project using "File -> Import project..." menu item, and it will automatically load SBT project structure and its dependencies.

Honeysucker answered 3/6, 2014 at 18:37 Comment(5)
This solution is almost perfect. IntelliJ seems to select Scala 2.10 as the language level in the Scala Facet, but has selected the 2.11 compiler. Adjusting the language level to Scala 2.11 closes the loop here.Hydria
The built-in plugin does not work in some circumstances. I frequently resort to sbt gen-idea. It has to do with refreshing projects after the build.sbt has changed.Hendley
jkschneider's tip fixed build issues for org.spec2, fwiwRunion
In case you're getting compilation errors right after importing the project, try close & reopen. Worked for me.Gadolinium
This is a solution too in case that you have the error Error accessing ~/.m2/repository/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jarDeferral
A
62
  1. Open File -> Project Structures -> Libraries, remove any scala sdk in it, e.g. scala-sdk-2.11.8 in the following image. enter image description here

  2. Click on +, then Scala SDK. enter image description here

  3. Select the right Scala SDK from the list, for me, it's Ivy-Scala-2.11.8 shown in the picture.enter image description here

  4. Select the current project(mine is spark-test), click OK. enter image description here

  5. Then click OK to close it. enter image description here

  6. Run again, it should work now.

Ambrogio answered 4/10, 2017 at 12:23 Comment(3)
I tried this, but all the libraries in step 3 were ghosted out as disabled. I could not select any of them.Chadbourne
This worked but i have literally no idea what changed?Stonyhearted
Key point here: if you have multiple modules, then in step 4 you must manually select all of the modules before clicking OK!Below
H
19

Since IDEA 13 you should use SBT support which is bundled with Scala plugin.

With it there is no need to add third-party SBT plugins and run special commands; just import the project using "File -> Import project..." menu item, and it will automatically load SBT project structure and its dependencies.

Honeysucker answered 3/6, 2014 at 18:37 Comment(5)
This solution is almost perfect. IntelliJ seems to select Scala 2.10 as the language level in the Scala Facet, but has selected the 2.11 compiler. Adjusting the language level to Scala 2.11 closes the loop here.Hydria
The built-in plugin does not work in some circumstances. I frequently resort to sbt gen-idea. It has to do with refreshing projects after the build.sbt has changed.Hendley
jkschneider's tip fixed build issues for org.spec2, fwiwRunion
In case you're getting compilation errors right after importing the project, try close & reopen. Worked for me.Gadolinium
This is a solution too in case that you have the error Error accessing ~/.m2/repository/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jarDeferral
V
7

I had the same issue with the .idea files generated by ./activator idea with play 2.3. A quick fix is to look in "Project Structure->modules" and note the name of the compiler library. For me it was "SBT: scala2.11.1". The look in "Project Structure->Libraries" and check the contents of this library. It should contain scala-compiler.jar, scala-library.jar, scala-reflect.jar. If this libraries are not present, add them (in my case they are located in ~/.sbt/boot/scala-2.11.1/lib).

Voluntaryism answered 13/7, 2014 at 3:7 Comment(2)
Hi Russell, I have the exact same problem. So what is the bug that causes this? a problem with activator?Sukkoth
running ./activator idea causes the problem to re-appear after this fix so I suppose it is a bug with the activator's .idea file generation. I haven't raised it with the typesafe team myself. Perhaps someone should do so...Voluntaryism
C
3

it looks like my answer is 9 years late, but the previous answers didn't work for me when I faced such a problem, so I'll leave my solution here.

File > Project structure > Global Libraries > in my case it was scala-sdk-2.13.8 > press minus sign (remove library) > press plus sign > select SDK that corresponds to your scala version ( ex. scala-sdk-2.12.10 in my case \ find you version in pom.xml file) > OK > Applay\OK

enter image description here

Cheesewood answered 21/6, 2023 at 10:37 Comment(1)
For multi-module projects, make sure you choose all of your modules that will need the scala-sdk. After doing this, my entire project compiled fine.Fractostratus
T
1

For IDEA 15 and project exported from Activator 1.3.5 only Russell's solution helped at the moment. I have fixed scala compiler library with adding 3 libraries located in ~/.sbt/boot/scala-2.11.1/lib to library's compiler classpath and classes. After indexing project I moved this library to global libraries of IDEA and it was saved there.

Tammeratammi answered 28/7, 2015 at 14:13 Comment(0)
P
1

I had the same issue.

If you are building your project using external sbt i.e sbt compile then it will create or add dependencies in libraries(all external dependency also) and scala sdk will be added as SBT:scala* based on version of your scala. So you can remove SDK with SBT as prefix and add proper SDK through Intellij.

File->Project Structure->Libraries

Remove SBT SDK and add it manually.

Pallua answered 21/9, 2017 at 10:10 Comment(0)
M
0

For me with IDEA 12, I fixed this issue when I unchecked the box for "Use external build" in Settings.Compiler.

Mimetic answered 10/8, 2016 at 16:42 Comment(0)
C
0

now is 2021 year, in Mac, use IntelliJ to run scala:

  • core logic
    • Mac: brew install scala
    • IntelliJ: open *.scala file, then according notice to auto config java JDK and Scala SDK
  • detailed steps: pls refer another post's answer
Cahill answered 10/3, 2021 at 8:45 Comment(0)
C
0

I'm an absolute Scala beginner. I was wanting to get up and running. I needed to create a Scala project, not a Java project with Scala library:

screenshot showing correct buttons to click

Chetchetah answered 8/9, 2021 at 12:21 Comment(0)
B
0

I had same issue for Maven multimodule project unexpectedly.

It happens with IntelliJ 2023.1.3.

Solution: simple re-import of Maven project helped.

Bridgetbridgetown answered 4/7, 2023 at 9:47 Comment(0)
G
0

I did the following and it worked for me -

  1. Click on 'Maven' in the right panel
  2. Click on 'Reload All Maven projects'
Guib answered 16/4 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.