IntelliJ IDEA
project cache
cleaning cache
Eclipse
development tools

IntelliJ clear cache: invalidate caches and clean like Eclipse

Codemia Knowledge Hub ·

Eclipse's "Clean" maps to two separate actions in IntelliJ IDEA: Build > Rebuild Project recompiles everything from scratch, and File > Invalidate Caches clears the IDE's indexes and internal caches. They fix different problems, and picking the right one avoids a needless full re-index.

Eclipse's Project > Clean deletes the compiled .class files in the output directory and forces a full rebuild. It does not touch Eclipse's workspace metadata or indexes. IntelliJ has no single button for exactly that, but the tools below cover the same ground and more.

Rebuild Project (build output only)

This is the closest match to Eclipse's Clean.

  1. Choose Build > Rebuild Project.
  2. IntelliJ deletes the contents of the output directory (typically out/ or target/) and compiles every source file from scratch.

Use it for:

  • Build errors that do not match your source code
  • Stale .class files causing NoSuchMethodError or ClassNotFoundException at runtime
  • Changes to compiler settings or annotation processors

There is no default shortcut. Assign one in Settings > Keymap by searching for "Rebuild Project."

For Maven or Gradle projects you can run the clean task directly, or double-click clean in the Maven/Gradle tool window:

bash
1# Maven
2mvn clean compile
3
4# Gradle
5./gradlew clean build

Invalidate Caches and Restart (IDE caches)

This clears IntelliJ's internal caches: the file index, symbol resolution data, VCS history cache and local history. It fixes IDE-level problems, not build problems.

  1. Choose File > Invalidate Caches.
  2. Tick the options you want:
    • Clear file system cache and Local History clears VCS-related caches
    • Clear VCS Log caches and indexes resets Git log data
    • Clear downloaded shared indexes removes pre-built indexes
  3. Click Invalidate and Restart.

Use it for:

  • "Cannot resolve symbol" errors when the code compiles fine
  • Navigation and auto-completion returning wrong results
  • An IDE that is noticeably slower than usual
  • After upgrading IntelliJ or switching JDK versions

After the restart IntelliJ re-indexes the whole project, which can take several minutes on a large codebase.

Reload the Maven or Gradle project

Many phantom errors come from the IDE's project model being out of sync with Maven or Gradle, not from corrupted caches. Reloading is faster and less disruptive than invalidating caches.

  • Maven: open the Maven tool window (View > Tool Windows > Maven) and click Reload All Maven Projects (the circular arrows).
  • Gradle: open the Gradle tool window and click Reload All Gradle Projects.
  • Keyboard: press Ctrl+Shift+A (Cmd+Shift+A on macOS) and type "Reload All Maven Projects" or "Reload All Gradle Projects."

IntelliJ re-reads pom.xml or build.gradle, downloads dependencies if needed and updates the module configuration.

Deleting the cache directories by hand

For problems the IDE tools do not fix, delete the cache directories while IntelliJ is closed.

Operating SystemCache Path
Windows%LOCALAPPDATA%\JetBrains\IntelliJIdea<version>\caches
macOS~/Library/Caches/JetBrains/IntelliJIdea<version>
Linux~/.cache/JetBrains/IntelliJIdea<version>
  1. Close IntelliJ IDEA completely.
  2. Go to the cache directory for your version.
  3. Delete the caches folder (or the whole version directory for a full reset).
  4. Restart IntelliJ. It rebuilds all caches from scratch.

To reset project-specific state, also delete the .idea directory in the project root. That removes all project-level IntelliJ configuration, so you must re-import the project. Back up run/debug configurations, code style settings and module structure first if they are not in version control.

Which one to use

MethodWhat It ClearsTime to RecoverBest For
Build > Rebuild ProjectCompiled .class filesSeconds to minutesBuild artifact issues
Maven/Gradle ReimportIDE project modelSecondsDependency sync issues
Invalidate CachesIDE indexes, symbol tables, VCS cacheMinutes (re-indexing)IDE navigation/resolution bugs
Manual cache deletionEverything (IDE-level)MinutesPersistent corruption
Delete .idea directoryProject configurationMust re-import projectConfiguration corruption

Start with the least disruptive option. Invalidating caches triggers a re-index that can take 5-10 minutes on large projects, while Rebuild Project fixes stale .class files in seconds. If you added a dependency and IntelliJ does not see it, reload the build before invalidating anything.

A clean build in CI

IntelliJ caches do not exist in CI, where Maven or Gradle runs directly, but a clean build still matters:

bash
1# Force a clean build in CI (Maven)
2mvn clean verify -U
3
4# Force a clean build in CI (Gradle)
5./gradlew clean build --no-build-cache

Maven's -U forces snapshot dependency updates. Gradle's --no-build-cache disables the build cache so the build is fully clean.

When the cache is not the real cause

  • You invalidate caches all the time. The root cause is usually a misconfigured project, incompatible plugins or too little memory. Check Help > Change Memory Settings and consider a 2-4 GB heap for large projects.
  • IntelliJ's compiler differs from the build tool's. IntelliJ's internal compiler drives real-time error highlighting, so it can show errors even when mvn compile succeeds. Make sure Settings > Build, Execution, Deployment > Compiler matches your build.
  • The JDK is wrong. Red squiggles and unresolved symbols are often caused by IntelliJ using a different JDK from your build tool. Check File > Project Structure > Project > SDK.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design