如何在 IDEA 中完全清理、重新解析和重建 Scala sbt 管理的项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29166100/
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
How to fully clean, re-resolve and rebuild a Scala sbt-managed project in IDEA?
提问by Tobber
TL;DR:How can I fully reconcile all dependencies in IntelliJ when SBT file changes
TL;DR:当 SBT 文件更改时,我如何完全协调 IntelliJ 中的所有依赖项
I have a SBT project setup in IntelliJ. For the most part if works like a charm, but it is quite a pain for me, to change the version of the dependencies and compilers.
我在 IntelliJ 中有一个 SBT 项目设置。在大多数情况下,if 就像一个魅力,但对我来说,更改依赖项和编译器的版本非常痛苦。
What I hope to do, is to update my SBT file, and click something like clean projectin IntelliJ, so it gets up to date.
我希望做的是更新我的 SBT 文件,然后在 IntelliJ 中单击诸如干净项目之类的内容,以便它是最新的。
The best menu item I have found is Rebuild project. It reads new dependencies, but keeps the old ones around, so External Libraries contains multiple versions of the Scala runtime and 3rd party libraries.
我发现的最好的菜单项是Rebuild project。它读取新的依赖项,但保留旧的依赖项,因此外部库包含多个版本的 Scala 运行时和第 3 方库。
To get around this I can close IntelliJ and delete all files in .idea/libraries. When I restart IntelliJ it will re-resolve the dependencies. It works, but manually deleting metadata files indicates that I am doing the wrong thing.
为了解决这个问题,我可以关闭 IntelliJ 并删除.idea/libraries. 当我重新启动 IntelliJ 时,它将重新解析依赖项。它有效,但手动删除元数据文件表明我做错了。
回答by Polymerase
回答by Brent Faust
When you save the SBT file, IntelliJ IDEA normally refreshes the project. But if it doesn't, you can do it manually.
保存 SBT 文件时,IntelliJ IDEA 通常会刷新项目。但如果没有,您可以手动进行。
There is a Refresh All SBT Projects button in the SBT Panel:
SBT 面板中有一个刷新所有 SBT 项目按钮:
On the occasion that IDEA is still confused, not finding packages you just added:
趁IDEA还糊涂的时候,没找到你刚刚添加的包:
From the File menu:
从文件菜单:
It's a pretty big hammer, requiring a restart of the app, and multi-minute rebuild of the IntelliSense index. But it's occasionally the only thing that will get IDEA to recognize your new SBT packages.
这是一个相当大的锤子,需要重新启动应用程序,并在多分钟内重建 IntelliSense 索引。但这有时是唯一能让 IDEA 识别您的新 SBT 包的方法。
回答by Daniel Langdon
Has happened to me before, and yes, is a PITA.
以前发生在我身上,是的,是一个 PITA。
What I usually do is to manually remove the dependencies from the project, all of them, then let sbt re-import what is actually needed. Don't do it on the UI though, since even having multiple selection, will ask for confirmation for EVERY dependency! (you will be clicking "Yes, I'm sure" for an hour), instead, go and delete directly from the .imlproject file on your .idea/modulesdirectory.
我通常做的是手动从项目中删除依赖项,所有这些,然后让sbt重新导入实际需要的内容。但是不要在 UI 上这样做,因为即使有多个选择,也会要求确认每个依赖项!(您将在一个小时内单击“是的,我确定”),而是直接从目录中的.iml项目文件中删除.idea/modules。
回答by cevaris
Another heavy hammer but seems to work.
另一个重锤,但似乎有效。
- Close IntelliJ
- Delete
.ideafolder - Import app from existing sources
- 关闭 IntelliJ
- 删除
.idea文件夹 - 从现有来源导入应用程序
回答by Max
try following steps:
尝试以下步骤:
- close IntelliJ
- backup whole project folder
- delete .idea folder
- delete target folder
- delete project/target folder
- reopen IntelliJ and import as a sbt project
- 关闭 IntelliJ
- 备份整个项目文件夹
- 删除 .idea 文件夹
- 删除目标文件夹
- 删除项目/目标文件夹
- 重新打开 IntelliJ 并作为 sbt 项目导入
Note this is only for SBT projects
请注意,这仅适用于 SBT 项目
回答by ialekseev
Agree, that's a PITA. Nothing helped me (I tried "Invalidate/Restart", removing files from ".idea/libraries" and restarting).
同意,那是 PITA。没有任何帮助(我尝试了“无效/重启”,从“.idea/libraries”中删除文件并重新启动)。
The only way to overcome the problem for me was to manually remove project-related folders from the IntelliJIdea cache. I removed these folders from the following places (I use OSX and IntelliJ-Idea 14):
解决这个问题的唯一方法是从 IntelliJIdea 缓存中手动删除与项目相关的文件夹。我从以下位置删除了这些文件夹(我使用 OSX 和 IntelliJ-Idea 14):
- /Users/{UserName}/Library/Caches/IntelliJIdea14/compiler/{ProjectName}
- /Users/{UserName}/Library/Caches/IntelliJIdea14/compile-server/{ProjectName}
- /Users/{UserName}/Library/Caches/IntelliJIdea14/compiler/{ProjectName}
- /Users/{UserName}/Library/Caches/IntelliJIdea14/compile-server/{ProjectName}
This helped me, hope it will save time for someone.
这对我有帮助,希望它能为某人节省时间。
回答by Yuchen Zhong
I was using different versions of sbt and scala across different proejcts and IntelJi got confused somehow. I am only able to resolve the issue by removing the sbtand ivy2cache folders:
我在不同的项目中使用了不同版本的 sbt 和 scala,而 IntelJi 不知何故弄糊涂了。我只能通过删除sbt和ivy2缓存文件夹来解决问题:
rm -rf ~/.ivy2
rm -rf ~/.sbt
回答by Saleh
If you are using the activator through a terminal/shell/command prompt use the following command:
如果您通过终端/外壳/命令提示符使用激活器,请使用以下命令:
activator clean
Or just "clean" on the sbt shell through intellij
或者只是通过 intellij 在 sbt shell 上“清理”
It should help reset things and next time you run or compile, it should go through it from scratch.
它应该有助于重置,下次运行或编译时,它应该从头开始。
回答by peter_pilgrim
IDEA 2016.2.4
想法 2016.2.4
None of these solutions worked for me.
这些解决方案都不适合我。
**** BEFORE YOU TRY THE ANY OF ABOVE. MAKE A BACKUP OF THE SBT / IDEA PROJECT IN QUESTION *****
**** 在您尝试上述任何一项之前。对有问题的 SBT/IDEA 项目进行备份 *****
If I updated the 'build.sbt' then the external library dependencies on the project view did not update. Moreover, the Project Structure still showed the old dependencies. No matter what I tried IDEA would not refresh.
如果我更新了“build.sbt”,那么项目视图上的外部库依赖项不会更新。此外,项目结构仍然显示旧的依赖项。无论我试过IDEA都不会刷新。
The only way I could get a partial restore was to copy the '.idea' folder from another machine. SBT plugin implementation is ****ed! I removed the '.idea/libraries' folder beforehand and then IDEA did not restore this folder. I tried many times importing the project again.
我能获得部分恢复的唯一方法是从另一台机器复制“.idea”文件夹。SBT 插件实现是****的!我事先删除了“.idea/libraries”文件夹,然后 IDEA 没有恢复这个文件夹。我多次尝试再次导入该项目。
Very bad :(
很坏 :(
ADDENDUM: I managed to get my project working. I think SBT with IDEA is no longer at fault entirely. It could be just possible that my Apache Ivy 2 cache might have been corrupted. So I executed the following commands:
附录:我设法让我的项目工作。我认为 SBT 和 IDEA 不再完全有错。我的 Apache Ivy 2 缓存可能已损坏。所以我执行了以下命令:
$ rm -rf ~/.ivy2/cache/org.scalatest/scalatest_2.11/*
$ rm -rf ~/.ivy2/cache/org.scalactic/scalactic_2.11/*
Restarted IDEA with invalidate cache under the file drop down menu item. This seemed to trigger some internal action in IDEA and SBT. I also tried manually adding add JARs throught the IDE, but it got massively confused. Moral of the story is to work on two different laptops machines daily and keep them updated.
使用文件下拉菜单项下的无效缓存重新启动 IDEA。这似乎在 IDEA 和 SBT 中触发了一些内部操作。我还尝试通过 IDE 手动添加添加 JAR,但它非常混乱。这个故事的寓意是每天在两台不同的笔记本电脑上工作并保持更新。
Also double check SBT from the command line works. I was using 0.13.12
还要从命令行仔细检查 SBT 的工作原理。我使用的是 0.13.12
$ sbt about
$ sbt clean
$ sbt test
Also recheck with the SBT dependencies plugin too.
还要重新检查 SBT 依赖项插件。
回答by Michail Michailidis
What worked for me was to:
对我有用的是:
1) Close IntelliJ
1)关闭IntelliJ
2) delete .idea/librariesinternals
2)删除 .idea/libraries内部
3) Start IntelliJ
3)启动IntelliJ
4) right-clicked pom.xml Maven > Reimport
4) 右键单击 pom.xml Maven > Reimport
After that there were no old versions and duplicate libraries in the External Libraries.
之后,外部库中没有旧版本和重复库。


