IntelliJ IDEA
project cache
cleaning cache
Eclipse
development tools

How to clean project cache in IntelliJ IDEA like Eclipse's clean?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

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:

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

When to use this:

  • Build errors that do not match your source code
  • Stale .class files causing runtime NoSuchMethodError or ClassNotFoundException
  • 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:

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

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:

  1. Go to File > Invalidate Caches.
  2. 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
  3. 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:

  1. Open the Maven tool window (View > Tool Windows > Maven).
  2. Click the Reload All Maven Projects button (circular arrows icon).

For Gradle projects:

  1. Open the Gradle tool window.
  2. 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 SystemCache Path
Windows%LOCALAPPDATA%\JetBrains\IntelliJIdea<version>\caches
macOS~/Library/Caches/JetBrains/IntelliJIdea<version>
Linux~/.cache/JetBrains/IntelliJIdea<version>

Steps:

  1. Close IntelliJ IDEA completely.
  2. Navigate to the cache directory for your version.
  3. Delete the caches folder (or the entire version directory for a full reset).
  4. 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

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

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:

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

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 .class files, Rebuild Project fixes it in seconds.
  • Not reimporting after changing pom.xml or build.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 .idea without backing up run configurations: The .idea directory contains your run/debug configurations, code style settings, and module structure. If these are not checked into version control, deleting .idea loses 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 compile succeeds, 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.

Course illustration
Course illustration

All Rights Reserved.