Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

java - Maven dependency cache not working on Gitlab Runner

I have spent an ample lot of time on this, and it doesn't seem to work. Have tried on multiple projects.

We host our gitlab runner ourselves (on our AWS via EKS) managed by Gitlab (SaaS). I want it to cache the maven dependencies.

When I configure it based on the reference example: https://gitlab.com/gitlab-org/gitlab-ci-yml/blob/master/Maven.gitlab-ci.yml , it still downloads all the dependencies every time.

stages:
  - test
  - pack

image: maven:3.6.1-jdk-8

variables:
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"


cache:
  paths:
    - .m2/repository


stylecheck_and_test:
  stage: test
  only:
    - tags
    - schedulers
    - web
    - triggers
    - branches
  script:
    - mvn $MAVEN_CLI_OPTS install -Dmaven.test.skip=true
    - mvn $MAVEN_CLI_OPTS clean test

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like local repo and cache paths are mismatch, Try with this.

stages:
  - test
  - pack

image: maven:3.6.1-jdk-8    

variables:
      MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=maven.repository -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
      MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
    
    
    cache:
      paths:
        - maven.repository/

stylecheck_and_test:
  stage: test
  only:
    - tags
    - schedulers
    - web
    - triggers
    - branches
  script:
    - mvn $MAVEN_CLI_OPTS install -Dmaven.test.skip=true
    - mvn $MAVEN_CLI_OPTS clean test

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...