50

My Maven installation (Windows 7 64-bit) has a .cache directory that is almost 3.5GB! It contains only a m2e directory. (I'm running Eclipse 4.3M7 with m2e.) Surely all the things inside aren't needed at present, and moreover I don't even know what this stuff is! I could find no Maven documentation of a .cache directory online.

So what are the .m2/repository/.cache and .m2/repository/.cache/m2e directories? Why do they have so much stuff from years ago? How do I dispose of all the stuff that's not needed anymore?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • 1
    FYI: for those using NetBeans, a similar cache is in C:\Users\\AppData\Local\NetBeans\Cache\8.1\mavenindex – Enwired Dec 08 '15 at 20:40

4 Answers4

46

In contrast to the other answers, make sure to keep .m2/*.xml (your settings) and .m2/repository (not strictly necessary to keep, but Maven will have to download half the Internet again).

Now, as for that .cache folder: if you open Eclipse, M2Eclipse will sometimes run a job akin to "Downloading repository indexes". These indexes allow you to quickly find an artifact using M2E's "Add dependency" wizard if you only know (part of) its artifact id. It needs to put the downloaded index files somewhere, and according to http://dev.eclipse.org/mhonarc/lists/m2e-users/msg02486.html the .cache folder is where they go:

Also note that m2e keeps at least three copies of each repository index. The original .gz files downloaded from remote repositories. A shared lucene instance used to optimize time spent processing gz files. And per-workspace lucene indexes. The first two are stored under local repository .cache/m2e directory, the last one is per-workspace.

The Lucene stuff they're talking about are extra optimized search databases, this makes it faster for M2E to search a given artifact if you only enter a partial artifact id or group id.

If I read http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01708.html correctly then it should be safe to remove them:

m2e caches lucene index in two places. Per-workspace indexes are stored under .metadata/.plugins/org.eclipse.m2e.core/nexus and there is also global cache in ~/.m2/repository/.cache/m2e/${m2e.version}.

Try cleaning the caches and see if the problem goes away.

Keep in mind though that M2E will notice the missing folder the next time you open Eclipse, so be prepared to wait while it downloads all repository indexes again!

JBert
  • 3,311
  • 24
  • 37
  • 2
    Now we're getting somewhere---thanks for the references! Now the directory structure seems a little less mystifying. I still don't know why all the crap from older m2e versions stick around, but I deleted them and all seems well so far. Thanks. – Garret Wilson May 08 '13 at 16:09
  • 1
    Uncheck "Preferences > Maven > Download repository index updates on startup" if you don't want the folder to come back (want to save 3GB and don't care about the "Add Dependency" feature). – Brian McCutchon May 11 '16 at 04:14
6

We can do a setting in the eclipse ide to disable .cache folder to increase.

Window->Preferences->Maven->Download repository index updates on startup

Disable this option and you will get rid of .cache problem!

dragonfly
  • 1,151
  • 14
  • 35
3

The m2e directory is the Eclipse Maven plugin's cache, not Maven's.

Georgemc
  • 369
  • 1
  • 5
  • 1
    Yes, the "m2e" part tipped me off to that. But that doesn't answer anything. I still don't know what type of stuff m2e stores in its cache. I still don't know of any documentation on the m2e cache directory. I still don't know what old stuff wasn't automatically deleted from the `m2e` directory. And I still don't know how how to safely dispose of stuff in this directory without harming the functionality of the m2e plugin. Thanks for responding, but I guess I was looking for a little more than "The `m2e` directory is for the m2e plugin." – Garret Wilson May 08 '13 at 15:23
1

The .m2/repository directory is your maven repository cache. Whenever Maven downloads something for you, it will cache it here. Usually it's safe to just delete the directory. Maven will recreate it for you. However, if you have dependencies that only exist in your repo cache, you'll have to reinstall them.

toolforger
  • 754
  • 7
  • 22
ilikeorangutans
  • 1,753
  • 1
  • 11
  • 14
  • 1
    I'm not talking about the entire `.m2` directory. I'm talking specifically about the `.m2/.cache` directory, and even more specifically the `.m2/.cache/m2e` directory. Can you address what goes here, why, and which files I can remove along with the ramifications? – Garret Wilson May 08 '13 at 14:14