by any chance does anyone know how to make it so b...
# gradle
x
by any chance does anyone know how to make it so bitbucket pipelines doesn't refetch gradle itself each time?
g
To do this you have 2 options: 1. Use CI image with preinstalled Gradle distribution and run builds using gradle command instead of ./gradlew 2. Cache ~/.gradle dir after each build (or only subdir with Gradle distributions). But I don't know are any of those options available on bitbucket CI or not
x
Bitbucket Pipelines has a "predefined" config for Gradle's cache, you don't even need to specify the location:
Copy code
#
# <https://hub.docker.com/_/gradle/>
image:
  name: gradle:4.4.1-jdk8

pipelines:
  default:
    - step:
        caches:
          - gradle
        script:
          - bash ./gradlew --version
          - bash ./gradlew check
Tweak the version according to your needs...that works flawlessly for me. GitLab is what's a hell complicated...
g
Hmm, Gradle dir in root of your project doesn't contain Gradle distribution, only wrapper jar, but this jar is small and should be bundled with project. So not sure that this somehow help. To cache Gradle itself you need ~/.gradle dir. But this image contains pre-installed Gradle so you can run project using it (your snippet uses Gradle wrapper instead) and avoid Gradle downloading, but I would prefer more flexible approach of wrapper (Gradle version updating together with project and downloading automatically)
x
On the documentation they aim for this one:
~/.gradle/caches
g
That's correct dir, you can tweak which caches do you need (dependencies, Gradle itself, build cache etc)
x
turns out there is a way... to cache the results of gradlew downloading gradle, but it's actually slower than just letting it do it đŸ˜•
g
cache the results of gradlew downloading gradle
What do you mean?
gradlew download gradle only once
it’s very convenient and allows to have reproducible builds
x
with something like pipelines, where your directories are transient, even enabling the "gradle" cache the gradle*zip that's downloaded is stored (slightly) elsewhere, thus every run it will be fetched again
turns out the fastest build there is to use the gradle docker image
(that doesn't work on werkcer)
g
You can use preinstalled gradle if you want, no problem with it. But it’s now your responsibility to keep it up to date with your project configs
Why you cannot cache
~/.gradle/caches
dir to cache gradle distribution?
We just cache it on CI
but you right, preinstalled gradle is also work
x
you can cache caches
you can even cache this
Copy code
[xeno@freyja gradle-plugin-bundle]$ ls ~/.gradle/wrapper/dists/gradle-4.8-
gradle-4.8-all/ gradle-4.8-bin/
which contains what will be downloaded every time
but turns out.... that cache is slower than actually letting gradlew retrieve it everytime
and using the docker container is actually faster that letting gradlew retrieve it everytime
by more seconds than just a fluke
g
yeah, you right. We actually cache ~/.gradle
About performance of cache restoration. It’s CI specific thing, we have own images and own server, so it’s instant for us.