How to clean project cache in IntelliJ IDEA like Eclipse's clean?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The equivalent of Eclipse's "Clean" in IntelliJ IDEA is a combination of two actions: Build > Rebuild Project (to recompile everything from scratch) and File > Invalidate Caches (to clear IDE indexes and internal caches). Unlike Eclipse, IntelliJ separates build output cleanup from IDE cache invalidation because they solve different problems. Understanding which one you need saves time and avoids unnecessary full re-indexing.
What Eclipse's "Clean" Actually Does
In Eclipse, Project > Clean deletes the compiled .class files in the output directory and forces a full rebuild. It does not clear Eclipse's internal workspace metadata or indexes. Developers reach for it when incremental compilation produces stale or incorrect build artifacts.
IntelliJ does not have a single button that does exactly this, but it provides more granular tools that cover the same ground and more.
Option 1: Rebuild Project (Build Output Only)
This is the closest equivalent to Eclipse's Clean. It deletes all compiled output and recompiles the entire project.
Steps:
- Go to Build > Rebuild Project in the menu bar.
- IntelliJ deletes the contents of the output directory (typically
out/ortarget/) and compiles every source file from scratch.
When to use this:
- Build errors that do not match your source code
- Stale
.classfiles causing runtimeNoSuchMethodErrororClassNotFoundException - After changing compiler settings or annotation processors
Keyboard shortcut: There is no default shortcut, but you can assign one via Settings > Keymap by searching for "Rebuild Project."
For Maven or Gradle projects, you can also run the clean task directly:
Or from within IntelliJ, open the Maven/Gradle tool window and double-click the clean task.
Option 2: Invalidate Caches and Restart (IDE Caches)
This clears IntelliJ's internal caches, including the file index, symbol resolution data, VCS history cache, and local history. It is more aggressive than a rebuild and addresses IDE-level issues rather than build issues.
Steps:
- Go to File > Invalidate Caches.
- In the dialog, check 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
- Click Invalidate and Restart.
When to use this:
- "Cannot resolve symbol" errors that do not match reality (code compiles fine)
- Navigation and auto-completion returning wrong results
- IDE running noticeably slower than usual
- After upgrading IntelliJ or switching JDK versions
After restart, IntelliJ re-indexes the entire project. This can take several minutes on large codebases.
Option 3: Reimport Build System (Maven/Gradle Sync)
Many "phantom error" issues in IntelliJ come from the IDE's project model being out of sync with Maven or Gradle, not from corrupted caches. Reimporting is faster and less disruptive than invalidating caches.
For Maven projects:
- Open the Maven tool window (View > Tool Windows > Maven).
- Click the Reload All Maven Projects button (circular arrows icon).
For Gradle projects:
- Open the Gradle tool window.
- Click the Reload All Gradle Projects button.
Or from the keyboard:
Press Ctrl+Shift+A (or Cmd+Shift+A on macOS) to open the action search, then type "Reload All Maven Projects" or "Reload All Gradle Projects."
This forces IntelliJ to re-read pom.xml or build.gradle, re-download dependencies if needed, and update module configurations.
Option 4: Manual Cache Deletion
For persistent issues not resolved by the IDE tools, you can manually delete cache directories while IntelliJ is closed.
Cache directory locations:
| Operating System | Cache Path |
| Windows | %LOCALAPPDATA%\JetBrains\IntelliJIdea<version>\caches |
| macOS | ~/Library/Caches/JetBrains/IntelliJIdea<version> |
| Linux | ~/.cache/JetBrains/IntelliJIdea<version> |
Steps:
- Close IntelliJ IDEA completely.
- Navigate to the cache directory for your version.
- Delete the
cachesfolder (or the entire version directory for a full reset). - Restart IntelliJ. It will rebuild all caches from scratch.
For project-specific caches, also delete the .idea directory in your project root. This removes all project-level IntelliJ configuration, so you will need to re-import the project afterward.
Comparison: Which Method to Use
| Method | What It Clears | Time to Recover | Best For |
| Build > Rebuild Project | Compiled .class files | Seconds to minutes | Build artifact issues |
| Maven/Gradle Reimport | IDE project model | Seconds | Dependency sync issues |
| Invalidate Caches | IDE indexes, symbol tables, VCS cache | Minutes (re-indexing) | IDE navigation/resolution bugs |
| Manual cache deletion | Everything (IDE-level) | Minutes | Persistent corruption |
Delete .idea directory | Project configuration | Must re-import project | Configuration corruption |
Automating Cache Cleanup in CI
In CI environments, IntelliJ caches do not apply (you are running Maven or Gradle directly). But the equivalent "clean build" concept still matters:
The -U flag in Maven forces dependency snapshot updates. The --no-build-cache flag in Gradle disables the build cache, ensuring a fully clean build.
Common Pitfalls
- Using "Invalidate Caches" when you need "Rebuild Project": Invalidating caches triggers a full re-index that can take 5-10 minutes on large projects. If the issue is just stale
.classfiles, Rebuild Project fixes it in seconds. - Not reimporting after changing
pom.xmlorbuild.gradle: IntelliJ does not automatically detect every build file change. If you add a dependency and IntelliJ does not see it, reimport before reaching for cache invalidation. - Deleting
.ideawithout backing up run configurations: The.ideadirectory contains your run/debug configurations, code style settings, and module structure. If these are not checked into version control, deleting.idealoses them. - Frequent cache invalidation as a habit: If you find yourself invalidating caches regularly, the root cause is likely a misconfigured project, incompatible plugins, or insufficient memory allocated to IntelliJ. Check Help > Change Memory Settings and consider increasing the heap to 2-4 GB for large projects.
- Confusing IntelliJ's compiler with the build tool's compiler: IntelliJ has its own internal compiler that runs for real-time error highlighting. Even if
mvn compilesucceeds, IntelliJ may show errors because its internal compiler uses different settings. Check Settings > Build, Execution, Deployment > Compiler to ensure the settings match. - Not checking JDK configuration: Many cache-related symptoms (red squiggles, unresolved symbols) are actually caused by IntelliJ pointing to a different JDK than your build tool. Verify under File > Project Structure > Project > SDK.
Summary
- Build > Rebuild Project is the direct equivalent of Eclipse's Clean. It deletes compiled output and forces a full recompilation.
- File > Invalidate Caches clears IDE-level indexes and caches. Use it for navigation bugs, resolution errors, and IDE slowness.
- Maven/Gradle reimport fixes dependency sync issues without touching IDE caches.
- Manual cache deletion is the nuclear option for persistent corruption. Close IntelliJ first and expect a full re-index on restart.
- Start with the least disruptive option (Rebuild or Reimport) before escalating to cache invalidation or manual deletion.
Related reading
- How to clear gradle cache?
- How to clear or clean specific pod from the local cocoapods cache
- How to clear react-native cache?
- How to combine sharding and consistent hashing within a distributed system?
- How to configure Kafka to behave like a FiFo queue?
- How to configure RabbitMQ using Active/Passive High Availability architecture
- how to configure redis ttl with spring boot 2.0
- How to control Flink jobs to be distributed/load-balanced properly amongst task-managers in a cluster?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.