title: Caching Maven dependencies in Gitlab-CI correctly
body: <p>I have configured and working following setup</p>
  
  <ul>
  <li>gitlab-ci, which uses docker-machine runner and uploads cache to S3</li>
  <li>maven build with configured caching</li>
  <li>caching correctly loads and uploads on each job</li>
  </ul>
  
  <p>But the problem is, that every time I run <code>mvn install</code>, 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.</p>
  
  <p><a href="https://i.stack.imgur.com/xn6mB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xn6mB.png" alt="enter image description here"></a></p>
  
  <p>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.</p>
  
  <p>How can I modify my build to force maven, to generate <strong>cacheable</strong> local repository?</p>
  
  <p>Simplified version of my <code>.gitlab-ci.yml</code>: </p>
  
  <pre class="lang-yaml prettyprint-override"><code>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/
  </code></pre>