Caching Maven dependencies in Gitlab-CI correctly
06:31 08 Jun 2019

I have configured and working following setup

  • gitlab-ci, which uses docker-machine runner and uploads cache to S3
  • maven build with configured caching
  • caching correctly loads and uploads on each job

But the problem is, that every time I run mvn install, something in the local maven repository changes (I assume it updates pom metadata) and gitlab runner keeps uploading new versions of the cache, on every single build.

enter image description here

It is still faster and more reliable to use this "busted" cache, than to download the deps from internet every time, but the upload can take a long time and I would like to shave off this extra time.

How can I modify my build to force maven, to generate cacheable local repository?

Simplified version of my .gitlab-ci.yml:

variables:
  # we have a custom java+maven image, that uses this ENV variable,
  # to auto-configure path where to put the local maven repository
  MAVEN_LOCAL_REPOSITORY: $CI_PROJECT_DIR/.cache/maven

job-build:
  stage: build
  image: internal-gitlab/java/maven:3.6-jdk8-alpine
  script:
    - mvn -B clean package
  cache:
    key: backend-dependencies
    paths:
      - .cache/
maven caching continuous-integration gitlab