Travis CI and Gradle caching

Hi! How should .travis.yml caching config look like, so that Travis does not repack caches after each and every build?

Currently Travis docs suggest to do:

  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/

    - $HOME/.gradle/caches/
    - $HOME/.gradle/wrapper/

(the rm bits most recently updated by me in

However, with Gradle 4.0 I see thrashing again because of these two files:


Could someone with better understanding of Gradle internals comment, what exactly should be cached on CI (that is, which files almost never change)?

1 Like

Ok, so now I am using

  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
  - rm -f  $HOME/.gradle/caches/*/fileHashes/fileHashes.bin
  - rm -f  $HOME/.gradle/caches/*/fileHashes/fileHashes.lock

which seems to do the trick, but I am not sure if I am accidentally deleting to much stuff.


I have the same question. From my understanding the *.lock files are just helpers to prevent gradle from modifying the cache while in usage (can be totally wrong).

Any idea if removing the following files from my cache before saving has any negative impact?


Found out that bitrise seem to use these exclude patterns:

excludePths := []string{

Is this a valid approach or do they exclude too much information for gradle caching to work?