I add cache property inside my gitlab-ci.yml
file in my Android project.
cache:
paths:
- .gradle/wrapper
- .gradle/caches
But in each pipeline when I run ./gradlew assemble
, It downloads all gradle dependencies which cause slow build time.
Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies. You can also delete the cached files under ~/. gradle/caches . With the next build Gradle would attempt to download them again.
The Gradle dependency cache consists of two storage types located under GRADLE_USER_HOME/caches : A file-based store of downloaded artifacts, including binaries like jars as well as raw downloaded meta-data like POM files and Ivy files.
all tiers. A cache is one or more files a job downloads and saves. Subsequent jobs that use the same cache don't have to download the files again, so they execute more quickly.
I'm doing it like this
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
cache:
paths:
- .gradle/wrapper
- .gradle/caches
Gitlab runner will not cache files outside of your project directory (e.g. ./gradle folder), So you need to cache all dependencies inside your project directory.
You can use -g
command which specifies the gradle user home directory.
For example you can call ./gradlew -g /cache assemble
to cache your dependencies in /cache
folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With