172

Sometimes the IDE makes some error because of the cache. In Eclipse, we can use clean to solve the problem. How can I do this in IntelliJ?

Pang
  • 9,564
  • 146
  • 81
  • 122
Marshall
  • 2,231
  • 4
  • 17
  • 15
  • 1
    Note for Maven users, the "Reload all Maven projects" button can help keep IntelliJ in sync with dependencies in pom.xml; this fixes more than just deleting the "target" folder. – Alexander Taylor Apr 06 '22 at 10:41

9 Answers9

292

Depending on the version you are running. It is basically the same just go to
File -> Invalidate caches, then restart Intellij
or
File -> Invalidate caches / Restart

The main difference is that in older versions you had to manually restart as cache files are not removed until you restart. The newer versions will ask if you also want to restart.

Older versions Newer Versions

As seen here on this official Jetbrains help page


You can also try delete caches manually in the system folder for your installed version. The location of this folder depends on your OS and version installed.

Windows Vista, 7, 8, 10
<SYSTEM DRIVE>\Users\<USER ACCOUNT NAME>\.<PRODUCT><VERSION>

Linux/Unix
~/.cache/JetBrains/<product><version>

Mac OS
~/Library/Caches/<PRODUCT><VERSION>

Read this for more details on cache locations.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
Java Devil
  • 10,629
  • 7
  • 33
  • 48
  • 3
    I have tried it,but sometimes it doesnot work.The code and setting of the project is right because after sometimes it went right. – Marshall Jul 10 '13 at 09:58
  • 2
    Even if that's what it does it pretty obvious so I don't understand why they cannot call it clean like in Eclipse Xcode and all the other IDEs. – sivi Jan 29 '15 at 09:32
  • 1
    Any way to prevent android studio from caching to aggressively in the first place? – Micro Jan 02 '16 at 18:14
  • 2
    FYI, at least by IntelliJ 2017.1 (preview), this menu item has changed to `File` > `Invalidate Caches / Restart`. – Basil Bourque Mar 10 '17 at 06:16
  • 2
    unfortunately, this will clear project history, which is sometimes undesirable. could we clear caches with history stay in place? – WebComer Apr 22 '17 at 12:15
  • Worth of saying, clicking just `Restart` is sufficient to clean the project, this will also avoid removing history. – cнŝdk Dec 03 '18 at 14:07
  • You can find a video with an example here: https://youtu.be/ctyoO6bZgjo – Vander Ig Oct 11 '22 at 03:28
  • You can find short tutorial on Invalidate Caches/ Restart here: https://youtu.be/CWI0edpXXWk – Vander Ig Oct 11 '22 at 03:48
  • Now, `system` folder doesn't exist and you must delete `caches` and ` Invalidate caches / Restart` menu doesn't work. At least for Windows 10. – Loran Jul 28 '23 at 01:25
11

Maybe not THE answer, but it's definitely AN answer.

If nothing else is working for you, go the nuclear option: Close IDEA and delete the ".../.IntelliJIdea/system" directory using your local file system tools.

The .IntelliJIdea directory is usually found in your home directory. Your IDE configuration is in the ".../.IntelliJIdea/config" directory, so it should be fine.

Obviously, this is not the "IDEA" way to do it and would be completely unsupported by JetBrains. Also - I don't use Android Studio so I dunno if this will cause problems, but there you go.

It's worked for me before when I've had problems getting IDEA to start and nothing else works to get me going. Maybe back up your entire .IntelliJIdea directory if you have a morbid fear of losing all your work >.<

Shorn
  • 19,077
  • 15
  • 90
  • 168
3

In addition to the .Intellij* files, and invalidating the cache, if you really want to clear everything out, then also delete the .idea folder and *.iml per-project files that IntelliJ also generates...

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
1

IntelliJ IDEA caches considerable amount of files for all projects that you have ever worked with in the IDE, hence the system cache may become overloaded.

Before you proceed, make note of these.

  • The caches will not be deleted until you restart IntelliJ IDEA.
  • Opening and closing a project without invalidating the cache does not result in deleting any cached files.
  • Local History is not deleted when you invalidate the cache unless you explicitly enable this option in the Invalidate Caches dialog.

You could do the following now via IDE to invalidate cache:

  1. From the main menu, select File | Invalidate Caches.

  2. In the Invalidate Caches dialog, Click Invalidate and Restart.

If you click Just restart, cache files won't be deleted.

You may have a look:

https://www.jetbrains.com/help/idea/invalidate-caches.html

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51
0

Try this:

Go into Settings (File > Settings or ctrl+alt+S). Under Project Settings, select the "Compiler" node. On the left, uncheck "Clear output directory on rebuild".

Note that this is a per project setting. If desired, change it in the project template settigs (Settings > Other Settings > Template Settings).

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • 5
    But if uncheck " "Clear output directory on rebuild",isn't it means it will not clear?I want to clear them. – Marshall Jul 10 '13 at 10:00
0

1) File -> Invalide Caches (in IDE IDEA)

2) Manually, got to C:\Users\\AppData\Local\JetBrains\IntelliJ IDEA \system\caches and delete

JetBrains: https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

27P
  • 1,183
  • 16
  • 22
0

Delete the "target" folder under the offending module. Then Build | Rebuild Project. Also make sure your clear the web browsers cache.

Philip Rego
  • 552
  • 4
  • 20
  • 35
0

For me, Invalidating Cache with all options did not solve it. My issue started when I upgraded from 2021-2022.2.3.

What did work was deleting the IntelliJ cache folders for 2021 & 2022. Their location is documented here: https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

For my Mac it was in located at: /Users/rsandberg/Library/Caches/JetBrains

After this, IntelliJ opened and worked as expected.

Ryan
  • 550
  • 4
  • 9
-3

Another solution was VCS -> Cleanup Project capture

TOTOR
  • 1
  • Nobody commented on the downvotes. Sadly. But I will not downvote it, just write why this answer is wrong: its about subversion, the Version Control, not the class cache of IntelliJ. – Brain Sep 21 '21 at 12:20