PabPabPab
PabPabPab

Reputation: 11

Cache gradle in Gitlab DIND

I'm not really familiar with Gitlab CI but recently arrived on a project and would like to speed up the pipeline. Currently we're wasting ~10min downloading the same Gradle dependencies over and over.

The pipelines is hosted on a private runner and uses Docker in Docker (which is probably why something is missing). It looks like an attempt was made to use cache, although it doesn't work.

The interesting part would be:

image: docker:stable
services:
  - name: docker:dind

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

variables:
  BUILD_IMAGE: "openjdk:8-jdk" 

build-job:
  image: $BUILD_IMAGE
  stage: build
  variables:
    GIT_STRATEGY: clone
    GIT_SUBMODULE_STRATEGY: normal
  script:
    - ./gradlew clean classes jasperCompilerTask -Dorg.gradle.daemon=false -x test
    - ./gradlew properties -q | grep "version:" | awk '{print $2}' >> project_version
  only:
    refs:
      - develop
      - octopus
      - merge_requests
    variables:
      - $BRANCH_TO_MERGE == null
  artifacts:
    paths:
      - project_version
      - deployment-scripts/deploy.sh

And in the job output we can see:

Updating/initializing submodules...
Restoring cache 00:01
Checking cache for default-8-non_protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script 10:29
$ export GRADLE_USER_HOME=`pwd`/.gradle
$ ./gradlew clean classes jasperCompilerTask -Dorg.gradle.daemon=false -x test
Downloading ...

And hundreds of lines of Downloading.

Do you have any idea on what could be missing ?

Upvotes: 0

Views: 1460

Answers (1)

Richard
Richard

Reputation: 2353

Add a printenv statement to see what value your GRADLE_USER_HOME variable is set to.

Add --info to your ./gradlew command to see exactly where dependencies are being downloaded. https://stackoverflow.com/a/57857095/2675670

build-job:
  image: $BUILD_IMAGE
  stage: build
  variables:
    GIT_STRATEGY: clone
    GIT_SUBMODULE_STRATEGY: normal
  script:
    - printenv GRADLE_USER_HOME
    - ./gradlew --info clean classes jasperCompilerTask -Dorg.gradle.daemon=false -x test
    - ./gradlew properties -q | grep "version:" | awk '{print $2}' >> project_version
  only:

Upvotes: 0

Related Questions