Scala keeps three caches and a target folder per project
Coursier, ivy and sbt each cache separately, and every project has its own build output. Where they are and what is safe.
A Scala setup on a Mac accumulates in four places at once: the Coursier cache, the older ivy cache, sbt's own boot and plugin caches, and a target directory in every project. None of them are cleaned by anything.
Where they are
du -sh ~/Library/Caches/Coursier ~/.cache/coursier \
~/.ivy2 ~/.sbt 2>/dev/null | sort -h
find ~ -maxdepth 5 -type d -name target 2>/dev/null \
-exec test -e '{}/../build.sbt' ';' -print0 | xargs -0 du -sh 2>/dev/null | sort -h | tailThe test for a build.sbt alongside is what keeps that last command from matching every other folder called target on the machine, including Rust projects.
What each holds
| Location | What it is | Safe to clear |
|---|---|---|
| Coursier cache | Downloaded artefacts, the modern one | Yes, redownloaded |
~/.ivy2 | Older dependency cache, often stale | Yes, and frequently unused |
~/.sbt | sbt versions, plugins, credentials | Careful: credentials live here |
Project target | Compiled output | Yes, rebuilt |
The ivy cache is often pure history
Modern sbt resolves through Coursier, so an ~/.ivy2 directory on a machine that has been through several sbt versions is often a complete cache that nothing has read in years. Checking its modification date settles it:
ls -ld ~/.ivy2 ~/.ivy2/cache 2>/dev/nullCredentials in ~/.sbt
This is the one caution on the page. Private repository credentials are conventionally kept in ~/.sbt, so clearing that folder wholesale can remove the file that lets your builds authenticate. Clear the caches inside it rather than the folder itself.
Compiled output across projects
Target folders are the largest total on most machines and the least risky to remove, in exactly the same way as Rust target folders and .NET bin and obj directories. A project you are not building does not need its compiled output kept.
Common questions
Where does Coursier store its cache on a Mac?
In ~/Library/Caches/Coursier, with some setups using ~/.cache/coursier. It holds downloaded artefacts and is safe to clear, at the cost of redownloading on the next build.
Can I delete the .ivy2 folder?
Usually yes. Modern sbt resolves through Coursier, so on many machines ~/.ivy2 is an old cache nothing reads. Check its modification date to confirm before removing it.
Is it safe to delete ~/.sbt?
Not wholesale. It holds sbt versions and plugins but conventionally also private repository credentials. Clear the caches inside it rather than the folder itself.
What is the largest part of a Scala setup?
Usually the target directories across projects, which hold compiled output and are rebuilt by the next build. The dependency caches are second and are also redownloadable.