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
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.
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.
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.
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.
To refresh IntelliJ after changes made in *.sbt files:
- Open the SBT Project pane (Menu View / Tool WIndows / SBT)
- Right click on your SBT project
- Select Refresh external project
When you save the SBT file, IntelliJ IDEA normally refreshes the project. But if it doesn't, you can do it manually.
There is a Refresh All SBT Projects button in the SBT Panel:
On the occasion that IDEA is still confused, not finding packages you just added:
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.
Another heavy hammer but seems to work.
- Close IntelliJ
- Delete
.idea
folder - Import app from existing sources
Has happened to me before, and yes, is a 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 .iml
project file on your .idea/modules
directory.
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
Note this is only for SBT projects