Your Search Bar For Shrewd Tips

How Do I Clear Maven Cache In Intellij?


If a Maven project in IntelliJ IDEA is stuck resolving dependencies, shows outdated artifacts, or keeps reporting errors after you change a version, clearing the Maven cache can help. The phrase “Maven cache” usually means the local repository on your computer, where Maven stores downloaded dependencies and plugins. IntelliJ also keeps its own project indexes and caches, which are separate.

To clear the right cache, first identify what is causing the problem. You can remove one problematic artifact, refresh the project from the Maven tool window, or rebuild the entire local repository if necessary. This guide explains each option, where Maven stores its files, and how to avoid deleting settings you still need.

What Does Clearing the Maven Cache Do?

Maven downloads project dependencies, build plugins, and other artifacts from remote repositories and saves them in a local repository. By default, that repository is the .m2/repository directory in your user home folder. On later builds, Maven can use these local files instead of downloading them again.

This speeds up builds, but cached files can occasionally cause trouble. A download may be incomplete, an artifact may have changed on a remote repository, or Maven may keep trying to resolve a version that is no longer available. Removing the relevant cached files makes Maven fetch them again the next time it builds the project.

Clearing the local repository does not normally remove your project’s source code or Maven configuration. However, Maven will need to download deleted dependencies and plugins again, so the next build may take longer and requires access to the relevant repositories.

Refresh Maven in IntelliJ First

Before deleting files, try reloading the Maven project. This asks IntelliJ to reread the project’s pom.xml files and update its project model. It is the quickest fix when you have changed a dependency, added a module, or updated a POM.

  • Open the project in IntelliJ IDEA.
  • Open the Maven tool window, usually from the right-hand tool window bar. If it is not visible, look for it under View > Tool Windows > Maven.
  • Click the Reload All Maven Projects button in the Maven tool window.
  • Wait for IntelliJ to finish importing and resolving the project.

You can also right-click a pom.xml file and choose the option to add it as a Maven project or reload it, depending on your IntelliJ version. If Maven is set to work offline, turn off Work offline in the Maven tool window before expecting it to download missing artifacts.

Reloading refreshes IntelliJ’s understanding of the project. It does not delete the local Maven repository, so it may not solve a corrupted or stale artifact. If the problem remains, clear the affected dependency from the repository.

Find Your Maven Local Repository

The default local repository location depends on your operating system:

  • Windows: C:\Users\YourName\.m2\repository
  • macOS: /Users/YourName/.m2/repository, also written as ~/.m2/repository
  • Linux: /home/YourName/.m2/repository, also written as ~/.m2/repository

Your Maven installation may use a different location. Maven can be configured with a custom localRepository value in its settings.xml file. In IntelliJ, check Settings or Preferences > Build, Execution, Deployment > Build Tools > Maven. The exact labels can vary by IntelliJ version. Review the Maven home and user settings file fields, then check the settings file for a <localRepository> entry.

Do not assume that deleting the default ~/.m2/repository directory will clear the cache if your project is configured to use a custom repository. Confirm the active location first.

Clear One Maven Dependency or Plugin

Removing only the problem artifact is usually the safest way to clear the Maven cache. Maven stores each artifact under folders that reflect its group ID, artifact ID, and version. For example, a dependency with the coordinates com.example:my-library:2.1.0 is typically in a path like .m2/repository/com/example/my-library/2.1.0.

  • Close or pause builds that are currently using the project.
  • Open the local repository directory in your file manager.
  • Navigate to the folder for the dependency or plugin that is causing the issue.
  • Delete the specific version folder. If Maven appears to be stuck on a failed download, also remove related files with names such as .lastUpdated.
  • Return to IntelliJ and reload the Maven project, or run a Maven build.

Maven will attempt to download the missing artifact again. If the issue affects every version of a particular artifact, you can remove that artifact’s entire folder. Avoid deleting unrelated folders: the more you remove, the more Maven must download again.

For a dependency, use the group ID and artifact ID shown in your POM or in the Maven tool window. For a plugin problem, look under the plugin’s coordinates in the repository. Plugin artifacts are cached alongside dependencies, but their folder paths are based on the plugin’s own group ID and artifact ID.

Clear the Entire Maven Cache

If many dependencies are corrupted, or you cannot identify which artifact is causing the failure, you can remove the entire local repository. This is a more disruptive option: Maven will have to download all required dependencies and plugins again.

  • Close IntelliJ IDEA, or at least stop any active Maven builds.
  • Find the active local repository location.
  • Delete the repository folder inside .m2. You can delete the whole repository directory or its contents.
  • Reopen IntelliJ and open the Maven tool window.
  • Make sure Maven is not in offline mode, then click Reload All Maven Projects.
  • Run a build and allow Maven to download the required artifacts.

You can also remove the repository from a terminal or command prompt, but double-check the path before running a recursive delete command. A typo could remove files outside the Maven cache. If you are unsure, use your file manager and move the directory to a temporary backup location instead of permanently deleting it. Once the project builds successfully, you can remove the backup.

Deleting .m2/repository is not the same as deleting the entire .m2 directory. The latter may contain your Maven settings.xml, which can include repository mirrors, proxy details, profiles, or credentials. Keep that configuration unless you have a separate reason to remove it.

Force Maven to Check for Updated Artifacts

Sometimes the files are not damaged; Maven simply has not checked a remote repository for a newer version. Run Maven with the -U option to force checks for updated snapshots and missing releases. In IntelliJ, open the Maven tool window, locate the project’s Maven goals field or run configuration, and add -U to the Maven command-line options. You can also run a command such as:

mvn -U clean verify

This command asks Maven to check for updates while running the build lifecycle through verification. The exact goal you need may differ by project; for example, use the goal your team normally runs if it has additional profiles or build requirements. The -U option does not erase the local repository. It is useful when Maven needs to recheck remote metadata or update snapshots, but it may not fix a genuinely corrupted artifact already on disk. In that case, remove the specific artifact and run the build again.

Should You Invalidate IntelliJ Caches?

IntelliJ’s IDE caches are different from Maven’s local repository. The IDE uses its own indexes and cached project information to provide features such as code completion, navigation, and project analysis. If the Maven command-line build works but IntelliJ still shows stale errors or unresolved symbols, refreshing the project and invalidating IDE caches may help.

To try this option, open File > Invalidate Caches in IntelliJ and select the appropriate invalidation and restart option. The wording can vary by version. IntelliJ will rebuild its indexes after restarting, which may take a little time.

Invalidating IntelliJ caches does not delete the Maven local repository or force Maven to download every dependency again. Likewise, deleting .m2/repository does not clear IntelliJ’s IDE indexes. If a dependency is absent from the local repository, focus on Maven. If Maven builds successfully outside IntelliJ but the editor remains confused, focus on reimporting the Maven project and refreshing IntelliJ’s caches.

Common Maven Cache Problems and Fixes

  • Dependency resolution fails after changing a version: Confirm the new version exists in a repository your project can access, reload Maven, and remove the old or failed version folder if needed.
  • Maven reports a failed or incomplete download: Delete the affected artifact’s version folder and any related .lastUpdated files, then build again with network access.
  • A snapshot does not appear to update: Check that the project uses a snapshot version and try a build with -U.
  • IntelliJ says a dependency is unresolved, but command-line Maven succeeds: Reload all Maven projects, check IntelliJ’s Maven settings and profiles, and consider invalidating IDE caches.
  • The project cannot download dependencies after clearing the cache: Check your internet connection, repository access, proxy settings, credentials, Maven settings file, and offline mode.
  • The wrong repository seems to be cleared: Check for a custom localRepository setting and confirm which Maven installation and settings file IntelliJ is using.

How to Prevent Repeated Cache Issues

Before clearing the whole Maven repository, read the complete error message and identify the coordinates of the missing or corrupted artifact. Targeted deletion saves time and avoids downloading unrelated libraries again. Also check that the version in your POM is correct and available from the configured repositories.

If your project depends on private repositories, preserve the relevant Maven settings and confirm that credentials and mirrors are configured correctly. A cache reset cannot fix an authorization failure or a repository outage. For team projects, follow the build instructions provided by the project, since custom profiles or settings may be required to resolve dependencies successfully.

Finally, avoid routinely deleting the entire cache as a first step. Maven’s local repository is designed to be reused. Refresh the project first, use -U when you need Maven to check for updates, and remove individual artifact folders when you can identify the problem.

Conclusion

To clear the Maven cache in IntelliJ, start by reloading all Maven projects. If that does not work, find the active local repository and delete the specific dependency or plugin folder that is causing the problem. Remove the entire .m2/repository directory only when a broader reset is necessary, and keep your Maven settings.xml safe.

Remember that Maven’s local repository and IntelliJ’s IDE caches are separate. Use Maven reloads, targeted artifact deletion, or the -U option for dependency-resolution issues. Use IntelliJ’s cache invalidation when the IDE’s indexes or displayed project information are stale. Choosing the right fix helps Maven download only what it needs and gets your IntelliJ project building again.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →