Gitlab CI gradle dependency cache

前端 未结 2 1917
名媛妹妹
名媛妹妹 2020-12-25 15:31

I\'m building android on Gitlab CI and downloading dependencies each time is annoying. I tried caching:

$HOME/.gradle/
$HOME/.gradle/caches/
$GRADLE_HOME/cac         


        
相关标签:
2条回答
  • 2020-12-25 15:46

    According to Kamil Trzciński

    We run the caching outside the build container. So you can cache absolute paths, but since only /builds and /cache is transferred you have no-way to cache container-local files.

    That means you need to put the gradle files into e.g. the /cache folder

    before_script:
      - export GRADLE_USER_HOME=cache/.gradle
    
    ...
    
    cache:
      key: "$CI_COMMIT_REF_NAME" #optional: per branch caching, can be omitted
      paths:
        - $GRADLE_USER_HOME/caches/
        - $GRADLE_USER_HOME/wrapper/
        - $GRADLE_USER_HOME/build-cache/
    

    The /cache folder will be kept automatically, but I keep the cache config for clarity.

    0 讨论(0)
  • 2020-12-25 16:00

    https://stackoverflow.com/a/35478988/2026105

    Turns out another post has the answer to this! There is a work around which is to run a before_script that sets the GRADLE_HOME to the directory of your project, which you can then slurp up with the cache directive.

    before_script:
        - export GRADLE_USER_HOME=`pwd`/.gradle
    
    cache:
      paths:
         - .gradle/wrapper
         - .gradle/caches
    
    build:
      stage: build
      script:
         - ./gradlew assemble
    
    test:
      stage: test
      script:
         - ./gradlew check
    
    0 讨论(0)
提交回复
热议问题