Skip to cookie settings

Where is the .m2 folder on Mac and how to clean the Maven repository

The .m2 folder is a hidden folder in your home directory. Here is what is inside it, how to see its size and what is safe to remove.

Part of: Mac disk cleanup for developers: every cache, what it costs to rebuild (Developers)

The .m2 folder is a hidden folder in your home folder: ~/.m2. Its repository subfolder is Maven’s local repository, a cache of every library and plugin Maven has downloaded. You can delete the repository. Maven downloads what it needs again on the next build. Keep settings.xml if you have one.

Maven is a build tool for Java projects. Folders with names that begin with a dot are hidden in Finder, which is why .m2 is easy to miss.

Find it and see its size

ls ~/.m2
du -sh ~/.m2/repository

The first command lists what is inside. On the Mac used to check this article, ~/.m2 held a repository folder and a wrapper folder. To open it in Finder, run open ~/.m2.

Maven lets you move the repository by setting a path in settings.xml. If ~/.m2/repository is missing or tiny and you do use Maven, look in ~/.m2/settings.xml for a localRepository entry.

What is inside

  • repository: downloaded libraries and plugins, organised by group and version. This is the large part.
  • settings.xml: your own configuration, such as mirrors and credentials for private servers. Small, and not a cache.
  • wrapper: copies of Maven versions downloaded by the Maven wrapper, a script some projects use to fetch the right Maven version.

Safe, risky, never

  • Safe: the repository folder, as a whole or in part. Cost: every library your next build needs downloads again.
  • Risky: deleting it before you must build offline, or when a library lives only on a private server you cannot reach. Libraries that you built and installed locally with Maven’s install step exist only in this folder, so removing them means you have to build them again.
  • Never: do not delete settings.xml as part of a cleanup. It may hold credentials and server settings that you cannot recover from the cache.

What it costs to get it back

The next build downloads libraries and plugins again. For a small project that is a minute. For a large project, or your first build after clearing everything, it can take much longer and use a lot of data. If you work on several projects, you pay for each one the first time you build it.

Locally installed artifacts are the trap. If you ran an install on a library of your own so another project could use it, it lives in ~/.m2/repository and nowhere else. Delete the folder and the other project cannot find it until you build the library again.

How to clean it

  1. Quit your IDE and any running build.
  2. Check the size and decide how much to remove.
  3. For a gentler approach, remove only subfolders of old libraries or groups you no longer use, instead of the whole repository.
  4. Move the chosen folders to the Trash in Finder and empty it. See why the Trash does not free space.
  5. Run a build of your main project to refill what you need.

Does it overlap with Gradle?

Not directly. Gradle has its own cache in ~/.gradle. A project can use both, and each downloads its own copies. Clearing one does not shrink the other. See how to clear the Gradle cache. Android projects use Gradle, so see Android Studio disk use too.

The full list of developer caches is in the developer cleanup guide.

Worked example: see what you would lose

Look inside the repository before you decide:

ls ~/.m2/repository

On the Mac used to check this article, the top level held folders such as com, org, io and net. These are the reversed domain names of the groups that publish libraries. Go one level deeper to see the names:

ls ~/.m2/repository/org

On that Mac this listed groups such as apache, assertj and codehaus. If you see a group that is your own company or project, check whether you built it locally. Libraries you installed yourself sit next to downloaded ones, and nothing marks them as special. A library you never published to a server is the part that cannot come back from the network.

A gentler step: remove one group

You do not need to remove the whole repository. Pick a group of old libraries and move that subfolder to the Trash. Maven downloads it again only if a project needs it. This is the lowest-cost way to trim the cache, and you can stop at any point.

If something goes wrong

  • The build says it cannot resolve a dependency. You are offline, or the library is gone from its server. Reconnect, or restore the folder from the Trash.
  • A project cannot find your own library. You removed a locally installed one. Build and install that library again.
  • Maven cannot reach a private server. Check settings.xml. It holds the server entries. Do not delete it.
  • The wrapper folder is large. Each Maven version the wrapper downloaded is stored there. Old ones can go, and the wrapper downloads them again if a project asks.

When not to clean

Do not clear the repository before a release build on a machine with no network. Do not clear it if you do not know which libraries you built yourself.

See the size in a scan

DiskJoy is our product. Its scan reads your disk and shows how large ~/.m2 is, read-only. Cleanup is not built yet, so DiskJoy does not delete it today.

Quick checklist

  1. du -sh ~/.m2/repository to see the size.
  2. Check settings.xml and keep it.
  3. Remember locally installed libraries.
  4. Move old subfolders, or the whole repository, to the Trash. Empty it.

Frequently asked questions

Where is the .m2 folder on a Mac?

It is a hidden folder named .m2 in your home folder, so the path is ~/.m2. The downloaded libraries are in ~/.m2/repository. Finder hides folders that start with a dot.

Can I delete the .m2 repository?

Yes. It is a cache of downloaded libraries, and Maven downloads what it needs again on the next build. Keep settings.xml if you have one in .m2, because it holds your own configuration.

Why is my .m2 folder so big?

Every library and plugin version Maven has ever downloaded for any project stays there, including old versions. It only grows unless you clean it.

Tags:MavenJava.m2

See what’s taking up space on your Mac

DiskJoy explains every item and removes nothing until you review it.
Download for Mac

Cookies on diskjoy.com

Your browser sends a Global Privacy Control signal. We honoured it: analytics and marketing cookies are off.

Necessary cookies run this site. Analytics shows us how it is used: if you accept it, Google receives data about your visit. Change this anytime in Cookie Settings. How Google uses data Cookie Policy Privacy policy

Customize

Purpose
Needed for the site to work and to remember your cookie choice.

Cookies

  • sy_consent - Stores your cookie choice (Retention: 12 months)

Other browser storage

  • sy_consent_pending (localStorage) - Queues your choice until it reaches our server (Retention: until deleted)
Purpose
Show us which pages are visited and how the site is used, so we can improve it. Provider: Google Ireland Ltd (Google Analytics 4).

Cookies

  • _ga - Distinguishes visitors to count them (Retention: 400 days)
  • _ga_TP2XMLG27P - Keeps the state of your current visit (Retention: 400 days)

Recipients

Data controller

Sylentis Group sp. z o.o.. Contact: support@diskjoy.com. Privacy policy

Google may process data outside the European Economic Area (EEA). Safeguards: EU-US Data Privacy Framework, standard contractual clauses.

Right to withdraw

You can withdraw consent at any time, as easily as you gave it. Withdrawal does not affect the lawfulness of processing before it.