scala 多个scala库导致intellij错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29489753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple scala libraies causing error in intellij?
提问by Kevin
I am using intellij 14 with scala 2.11.6 installed using home brew and symlink using
我正在使用 intellij 14 和 scala 2.11.6 安装使用 home brew 和符号链接使用
ln -s /usr/local/Cellar/scala/2.11.6/libexec/src /usr/local/Cellar/scala/2.11.6/src
ln -s /usr/local/Cellar/scala/2.11.6/libexec/lib /usr/local/Cellar/scala/2.11.6/lib
mkdir -p /usr/local/Cellar/scala/2.11.6/doc/scala-devel-docs
ln -s /usr/local/Cellar/scala/2.11.6/share/doc/scala /usr/local/Cellar/scala/2.11.6/doc/scala-devel-docs/api
I tried running a simple hello world but run into the following issue.
我尝试运行一个简单的 hello world,但遇到了以下问题。
Error:scalac: Multiple 'scala-library*.jar' files (scala-library.jar, scala-library.jar, scala-library.jar) in Scala compiler classpath in Scala SDK scala-sdk-2.11.6
Edit:
编辑:
So I check the compiler class path on global libraries and apparently there are multiple scal-library.jar
所以我检查了全局库上的编译器类路径,显然有多个 scal-library.jar
file:///usr/local/Cellar/scala/2.11.6/idea/lib/scala-library.jar
file:///usr/local/Cellar/scala/2.11.6/lib/scala-library.jar
file:///usr/local/Cellar/scala/2.11.6/libexec/lib/scala-library.jar
Does anyone know why?
有谁知道为什么?
回答by Niels
Maybe you have used
也许你用过
/usr/local/Cellar/scala/2.11.6/
as the path for Scala SDK?
作为 Scala SDK 的路径?
When you install scala with homebrew that path will contain not only the scala libraries, but also a symlink with the relevant libraries for intellij. So if you use the top-level install directory intellij will find the libraries twice.
当您使用自制软件安装 scala 时,该路径将不仅包含 scala 库,还会包含与相关库的符号链接 intellij。因此,如果您使用顶级安装目录,intellij 将两次找到这些库。
Instead you should use
相反,你应该使用
/usr/local/Cellar/scala/2.11.6/idea/lib
回答by legramira
I had the same issue than you experimented and the solution, actually very easy, was actually erasing the .idea folder from the project, the problem is that the configuration inside of this folder (containing the set ups for example for the test, VCS, the runs, etc) gets corrupted with double entries (probably cos you update your Scala version), once you do this and reopen the project in Intellij the IDEA will generate a fresh new configuration for you.
我遇到了与您实验相同的问题,解决方案实际上非常简单,实际上是从项目中删除 .idea 文件夹,问题在于该文件夹内的配置(包含设置,例如测试、VCS、运行等)被双重条目损坏(可能是因为您更新了 Scala 版本),一旦您这样做并在 Intellij 中重新打开项目,IDEA 将为您生成一个全新的配置。
回答by Eeelijah
This worked for me. I'm using Idea 2019.2.2 and Windows 10.
这对我有用。我正在使用 Idea 2019.2.2 和 Windows 10。
In the folder .idea/libraries/I had two files: sbt__org_scala_lang_scala_library_2_13_0_jar.xmland sbt__org_scala_lang_scala_library_2_13_0_jar2.xml.
在文件夹中.idea/libraries/我有两个文件:sbt__org_scala_lang_scala_library_2_13_0_jar.xml和sbt__org_scala_lang_scala_library_2_13_0_jar2.xml.
I deleted the second file. Then I opend the first one and there were duplicate lines:
我删除了第二个文件。然后我打开第一个,有重复的行:
<root url="file://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/jline/jline/2.14.6/jline-2.14.6.jar" />
<root url="file://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.0/scala-compiler-2.13.0.jar" />
<root url="file://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.0/scala-compiler-2.13.0.jar" />
<root url="file://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.0/scala-library-2.13.0.jar" />
<root url="file://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.0/scala-library-2.13.0.jar" />
<root url="file://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.0/scala-reflect-2.13.0.jar" />
So I deleted duplicates and errors disappeared. Hope this will help someone else.
所以我删除了重复项,错误消失了。希望这会帮助别人。
回答by Toby Eggitt
2019 update... I'm running Ubuntu Linux and IntelliJ community 2019.1 with sbt 2.13.1 and got the exact same error. I also found that if I built directly from sbt with "runMain package.MyClass" it worked, so I knew it must be an IntelliJ problem, not a "real" problem.
2019 年更新...我正在使用 sbt 2.13.1 运行 Ubuntu Linux 和 IntelliJ 社区 2019.1 并得到完全相同的错误。我还发现,如果我使用“runMain package.MyClass”直接从 sbt 构建,它会起作用,所以我知道这一定是 IntelliJ 问题,而不是“真正的”问题。
Anyway, I found the file .idea/libraries/sbt.. lots of crazy long name ... scala_library_2_13_1_jar.xml.
无论如何,我找到了文件 .idea/libraries/sbt.. 很多疯狂的长名称...... scala_library_2_13_1_jar.xml。
In it, there was an XML block , and in that block, two entries were duplicated: I first noticed the scala-library one, and after deleting that, the error report came up about the scala-compiler duplicate too. After deleting both duplicates, my build is now working.
其中,有一个 XML 块,在该块中,有两个条目重复:我首先注意到了 scala-library 一个,删除它后,错误报告也出现了关于 scala-compiler 重复的错误报告。删除两个重复项后,我的构建现在可以工作了。
回答by Cindy
I also ran into that error. The fix I found was to remove the duplicate scala-library in the .iml file generated by intellij.
我也遇到了那个错误。我发现的修复方法是删除 Intellij 生成的 .iml 文件中重复的 scala-library。
Basically I located the relevant .iml file by grepping the scala version, and found that two scala-library in that file. I removed the scala 2.11 version, and then it works.
基本上,我通过 grepping scala 版本找到了相关的 .iml 文件,并在该文件中找到了两个 scala-library。我删除了 Scala 2.11 版本,然后它就可以工作了。
回答by Centurion
Remove the following line in build.sbt:
删除 build.sbt 中的以下行:
...
scalaVersion := "2.13.0"
...
Try rebuilding and running it again
尝试重建并再次运行它
回答by Hartmut P.
Having similar symptoms, but on a Ubuntumachine, not using brew:
有类似的症状,但在一Ubuntu台机器上,不使用brew:
I am using /usr/share/sbt/bin/sbt-launch.jaras launcher. To fix the mentioned problem, I've had to purge the directories 1) project, 2) targetand 3) .ideaof the relevant Scala projects, doing sbt refresh in IntelliJ (View- Tool Windows-> sbt, hit the Reimport all sbt projectsicon), and rebuild all modules afterwards.
我/usr/share/sbt/bin/sbt-launch.jar用作启动器。为了解决上述问题,我必须清除相关 Scala 项目的目录 1) project、 2)target和 3) .idea,在 IntelliJ 中执行 sbt 刷新(View- Tool Windows-> sbt,点击Reimport all sbt projects图标),然后重建所有模块。
As a last step, when the error occurs further, switch over to Ubuntu shell / terminal, and do a sbt clean compilein the problematic project folder. Fix the compile issues if some are occuring. If this does not help, change scalaVersionin build.sbte.g. from 2.12.9to 2.12.8(the error occurs more often with 2.12.9), remove scalaOrganizationdefinition (but keep organization). Repeat the sbt refreshof IntelliJ. OMG.
最后一步,当错误进一步发生时,切换到 Ubuntu shell/终端,并sbt clean compile在有问题的项目文件夹中执行。如果出现编译问题,请修复编译问题。如果这没有帮助,改变scalaVersion在build.sbt例如从2.12.9到2.12.8(错误发生更多的时候2.12.9),删除scalaOrganization定义(但保留organization)。重复sbt refreshIntelliJ。我的天啊。
回答by user11435723
Delete multiple versions of scala-library in sbt, leaving one.
删除sbt中多个版本的scala-library,留下一个。
回答by Tim Biegeleisen
You have JAR files from multiple versions of scala-library.jar. In order to make the error go away you will have to delete the duplicates. To figure out which version you want to keep, you can view the manifest file inside each JAR:
您有来自多个版本的 JAR 文件scala-library.jar。为了使错误消失,您必须删除重复项。要确定要保留哪个版本,可以查看每个 JAR 中的清单文件:
META-INF/MANIFEST.MF
Inside the manifest file you should see something like this:
在清单文件中,您应该看到如下内容:
Manifest-Version: 1.0
Class-Path:
Implementation-Title: Scala-Library
Implementation-Version: 2.11.4
The error is happening because IntelliJ cannot figure out which version of a given Scala class to use.
发生错误是因为 IntelliJ 无法确定要使用给定 Scala 类的哪个版本。
回答by Sathiraumesh
To fix the problem go to project structure in intellij and go to global libraries
It should be like this
要解决问题,请转到intellij中的项目结构并转到全局库它应该是这样的
After that remove all the scala SDKs by hitting the - mark
之后通过点击 - 标记删除所有 scala SDK
Next, click the + and choose your Scala SDK version to add
接下来,单击 + 并选择要添加的 Scala SDK 版本
After that please make sure to apply the changes and re-run the program
之后,请确保应用更改并重新运行程序

