简体   繁体   English

如何在IDEA中完全清理,重新解析和重建Scala sbt管理的项目?

[英]How to fully clean, re-resolve and rebuild a Scala sbt-managed project in IDEA?

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. 我在IntelliJ中设置了SBT项目。 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. 在大多数情况下,如果像魅力一样工作,但对我来说,改变依赖项和编译器的版本是相当痛苦的。

What I hope to do, is to update my SBT file, and click something like clean project in IntelliJ, so it gets up to date. 我希望做的是更新我的SBT文件,然后单击IntelliJ中的清洁项目 ,这样它就是最新的。

The best menu item I have found is Rebuild project . 我找到的最好的菜单项是Rebuild项目 It reads new dependencies, but keeps the old ones around, so External Libraries contains multiple versions of the Scala runtime and 3rd party libraries. 它读取新的依赖项,但保留旧的依赖项,因此外部库包含Scala运行时和第三方库的多个版本。

To get around this I can close IntelliJ and delete all files in .idea/libraries . 为了解决这个问题,我可以关闭IntelliJ并删除.idea/libraries所有文件。 When I restart IntelliJ it will re-resolve the dependencies. 当我重新启动IntelliJ时,它将重新解析依赖项。 It works, but manually deleting metadata files indicates that I am doing the wrong thing. 它可以工作,但手动删除元数据文件表明我做错了。

To refresh IntelliJ after changes made in *.sbt files: 在* .sbt文件中进行更改后刷新IntelliJ:

  • Open the SBT Project pane (Menu View / Tool WIndows / SBT) 打开SBT项目窗格(菜单视图/工具窗口/ SBT)
  • Right click on your SBT project 右键单击您的SBT项目
  • Select Refresh external project 选择刷新外部项目

在此输入图像描述

When you save the SBT file, IntelliJ IDEA normally refreshes the project. 保存SBT文件时,IntelliJ IDEA通常会刷新项目。 But if it doesn't, you can do it manually. 但如果没有,你可以手动完成。

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: 从文件菜单:

使缓存ScreenShot无效

It's a pretty big hammer, requiring a restart of the app, and multi-minute rebuild of the IntelliSense index. 这是一个相当大的锤子,需要重新启动应用程序,并且需要多分钟重建IntelliSense索引。 But it's occasionally the only thing that will get IDEA to recognize your new SBT packages. 但偶尔也会让IDEA认识到你的新SBT套装。

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. 我通常做的是从项目中手动删除所有依赖项,然后让sbt重新导入实际需要的东西。 Don't do it on the UI though, since even having multiple selection, will ask for confirmation for EVERY dependency! 不要在UI上执行此操作,因为即使有多个选择,也会要求确认每个依赖项! (you will be clicking "Yes, I'm sure" for an hour), instead, go and delete directly from the .iml project file on your .idea/modules directory. (您将点击“是的,我确定”一小时),而是直接从.idea/modules目录上的.iml项目文件中删除。

try following steps: 尝试以下步骤:

  1. close IntelliJ 关闭IntelliJ
  2. backup whole project folder 备份整个项目文件夹
  3. delete .idea folder 删除.idea文件夹
  4. delete target folder 删除目标文件夹
  5. delete project/target folder 删除项目/目标文件夹
  6. reopen IntelliJ and import as a sbt project 重新打开IntelliJ并导入为sbt项目

Note this is only for SBT projects 请注意,这仅适用于SBT项目

Another heavy hammer but seems to work. 另一个重锤似乎工作。

  1. Close IntelliJ 关闭IntelliJ
  2. Delete .idea folder 删除.idea文件夹
  3. Import app from existing sources 从现有来源导入应用

I was using different versions of sbt and scala across different proejcts and IntelJi got confused somehow. 我在不同的项目中使用了不同版本的sbt和scala,并且IntelJi以某种方式感到困惑。 I am only able to resolve the issue by removing the sbt and ivy2 cache folders: 我只能通过删除sbtivy2缓存文件夹来解决问题:

rm -rf ~/.ivy2
rm -rf ~/.sbt

If you are using the activator through a terminal/shell/command prompt use the following command: 如果通过终端/ shell /命令提示符使用激活器,请使用以下命令:

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. 它应该有助于重置事物,下次运行或编译时,它应该从头开始。

Agree, that's a PITA. 同意,这是一个PITA。 Nothing helped me (I tried "Invalidate/Restart", removing files from ".idea/libraries" and restarting). 没有什么帮助我(我尝试“无效/重启”,从“.idea / libraries”中删除文件并重新启动)。

The only way to overcome the problem for me was to manually remove project-related folders from the IntelliJIdea cache. 解决这个问题的唯一方法是从IntelliJIdea缓存中手动删除与项目相关的文件夹。 I removed these folders from the following places (I use OSX and IntelliJ-Idea 14): 我从以下地方删除了这些文件夹(我使用OSX和IntelliJ-Idea 14):

  • /Users/{UserName}/Library/Caches/IntelliJIdea14/compiler/{ProjectName} /用户/ {名} / Library /缓存/ IntelliJIdea14 /编译器/ {项目名}
  • /Users/{UserName}/Library/Caches/IntelliJIdea14/compile-server/{ProjectName} /用户/ {名} / Library /缓存/ IntelliJIdea14 /编译服务器/ {项目名}

This helped me, hope it will save time for someone. 这对我有所帮助,希望它能为某人节省时间。

IDEA 2016.2.4 IDEA 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. 如果我更新了'build.sbt',那么项目视图上的外部库依赖项就不会更新。 Moreover, the Project Structure still showed the old dependencies. 此外,项目结构仍显示旧的依赖项。 No matter what I tried IDEA would not refresh. 无论我尝试什么,IDEA都不会刷新。

The only way I could get a partial restore was to copy the '.idea' folder from another machine. 我可以获得部分恢复的唯一方法是从另一台机器复制'.idea'文件夹。 SBT plugin implementation is ****ed! SBT插件实现已经过了! I removed the '.idea/libraries' folder beforehand and then IDEA did not restore this folder. 我事先删除了'.idea / libraries'文件夹,然后IDEA没有恢复此文件夹。 I tried many times importing the project again. 我多次尝试导入项目。

Very bad :( 很坏 :(

ADDENDUM: I managed to get my project working. 附录:我设法使我的项目有效。 I think SBT with IDEA is no longer at fault entirely. 我认为与IDEA的SBT不再完全是错误的。 It could be just possible that my Apache Ivy 2 cache might have been corrupted. 可能我的Apache Ivy 2缓存可能已损坏。 So I executed the following commands: 所以我执行了以下命令:

$ 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. 在文件下拉菜单项下重新启动具有无效缓存的IDEA。 This seemed to trigger some internal action in IDEA and SBT. 这似乎引发了IDEA和SBT的一些内部行动。 I also tried manually adding add JARs throught the IDE, but it got massively confused. 我也试过在IDE中手动添加添加JAR,但是它被大量混淆了。 Moral of the story is to work on two different laptops machines daily and keep them updated. 故事的道德是每天在两台不同的笔记本电脑上工作并保持更新。

Also double check SBT from the command line works. 还可以从命令行中仔细检查SBT。 I was using 0.13.12 我使用的是0.13.12

$ sbt about
$ sbt clean
$ sbt test

Also recheck with the SBT dependencies plugin too. 还要重新检查SBT依赖项插件。

What worked for me was to: 对我有用的是:

1) Close IntelliJ 1)关闭IntelliJ

2) delete .idea/libraries internals 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. 之后,外部库中没有旧版本和重复库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM