zapatilla
zapatilla

Reputation: 1833

Why does IntelliJ seem to import my scala libraries twice?

I have just started trying to use Scala with IntelliJ. I created a new project as per the instructions in:

https://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html

I installed scala 2.12.6 using Homebrew and selected that when creating my new Scala project in IntelliJ.

For some reason, under External Libraries, I have every jar inside the scala installation twice:

IntelliJ_Scala_Libraries

I created a hello world and when I try to run it, I get this error:

Error:scalac: Multiple 'scala-library*.jar' files (scala-library.jar, scala-library.jar) in Scala compiler classpath in Scala SDK scala-sdk-2.12.6

However inside the Scala libraries folder there is only one jar of each.

I'm not sure what I'm doing wrong here. I've tried other versions of Scala, but got the same results. I tried to delete one of the jars, and deleted the actual only copy of it and I had to reinstall scala.

Upvotes: 1

Views: 1803

Answers (3)

Alagusundaram
Alagusundaram

Reputation: 1

I am using windows & intelliJ combination, I faced the same issue since i am new to scala, as usual i was searching in google and spend much time in resolving my issue.

Most of the suggestions are for linux based, please try the below, in my case it worked out.

1) Check your iml file and verify the orderEntry. By default if you download sbt, it would contain 2 set of libraries. I downloaded the SBT version 1.2.7, it by default contain 2 set of libraries. one with 2.12.0 and another with 2.12.7.

2) The project iml file of mine had with scala SDK 2.12.0 which was the reason for my issues, I edited that to change to 2.12.7 which automatically changed the order with 2.12.7 first and solved my issue. This solved my problem.

Upvotes: 0

zapatilla
zapatilla

Reputation: 1833

I just found the problem. When I right click on the library in the project explorer, I saw the paths for each jar file. It seems like in the scala installation by homebrew made in /usr/local/Cellar/scala/<version> there are two folders that contain the same jars:

/usr/local/Cellar/scala/<version>/idea/lib

and

/usr/local/Cellar/scala/<version>/libexec/lib

Since I was importing in IntelliJ this path /usr/local/Cellar/scala/<version>, all jars from both folders were imported, causing the duplication.

Solution is to import just one of those two options. I have now set up IntelliJ to just use as external libraries /usr/local/Cellar/scala/<version>/idea/lib and it seems to work!

Upvotes: 1

ira wati
ira wati

Reputation: 89

@Zapatilla,

Follow this,

Click File --> Project Structure; Select Modules; Select Dependencies

You should see scala-sdk-2.12.6 there. Remove it by selecting it first and then clicking the "-" sign below.

Once done click the "+" button and select "2. Library --> Scala from SDK"; Select the appropriate version and hit Apply;Ok.

This should resolve it.

Upvotes: 1

Related Questions