Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear gradle cache?

I'm trying to use Android Studio, and the first time I boot it up, it takes like 45 MINUTES to compile... If I don't quit the application, it is okay - each subsequent compilation/running the app will take around 45 seconds.

I've tried to check some of my caches: there's a .gradle/caches folder in my home directory, and it's contains 123 MB.

There's also a .gradle folder in my project folder... one of the taskArtifacts was like 200 MB. I'm scared to just randomly nuke them both. What parts of the folders are safe to delete?

Is there a better explanation for why my Android Studio is taking forever to run the gradle assemble task upon first time loading the application?

Do I also have to clear the intellij cache too?

like image 951
David T. Avatar asked Apr 12 '14 02:04

David T.


People also ask

Can I clear Gradle caches?

gradle/caches directory holds the Gradle build cache. So if you have any error about build cache, you can delete it. The --no-build-cache option will run gradle without the build cache.

How do you clean Gradle?

If you wish to clean (empty) the build directory and do a clean build again, you can invoke a gradle clean command first and then a gradle assemble command. Now, fire the gradle assemble command and you should have a JAR file that is named as <name>-<version>. jar in the build/libs folder.

Where is the Gradle cache?

Gradle caches artifacts in USER_HOME/. gradle folder. The compiled scripts are usually in the . gradle folder in your project folder.

What is the Gradle cache?

The Gradle Build Cache is designed to help you save time by reusing outputs produced by previous builds. It works by storing (locally or remotely) build outputs, and allowing builds to fetch these outputs from the cache when it determines that inputs have not changed.


2 Answers

Gradle cache is located at

  • On Windows: %USERPROFILE%\.gradle\caches
  • On Mac / UNIX: ~/.gradle/caches/

You can browse to these directory and manually delete it or run

rm -r $HOME/.gradle/caches/ 

on UNIX system. Run this command will also force to download dependencies.


UPDATE

Clear the Android build cache of current project

NOTE: Android Studio's File > Invalidate Caches / Restart doesn't clear the Android build cache, so you'll have to clean it separately.

On Windows:

gradlew cleanBuildCache 

On Mac or UNIX:

./gradlew cleanBuildCache 

UPDATE 2

This article Put your Android Studio on a diet gives more details on Android Studio caches

like image 159
Bao Le Avatar answered Sep 19 '22 13:09

Bao Le


As @Bradford20000 pointed out in the comments, there might be a gradle.properties file as well as global gradle scripts located under $HOME/.gradle. In such case special attention must be paid when deleting the content of this directory.

The .gradle/caches directory holds the Gradle build cache. So if you have any error about build cache, you can delete it.

The --no-build-cache option will run gradle without the build cache.

Daemon on MS Windows If you're on Windows, you'll need to kill the daemon before it allows you to clear those directories. See Kill all Gradle Daemons Regardless Version? for more info.

like image 26
Opal Avatar answered Sep 17 '22 13:09

Opal