gradlegithub-actions

how to reuse gradle cache in GitHub workflow


I am trying to to keep the gradle cache in my GitHub workflow, but it is not working. I am new to gradle and am struggling to find out how/why I am unable to keep the gradle cache between workflow builds of my project

in my GitHub workflow file, I have two gradle caches. One of the gradle cache and the other one is the gradle wrapper:

      - name: Setup Gradle Dependencies Cache
        uses: actions/cache@v2
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts') }}
      - name: Setup Gradle Wrapper Cache
        uses: actions/cache@v2
        with:
          path: ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}

Locally a ./gradlew clean followed by a ./gradlew build will build my project in about 33 seconds... On GitHub, it takes 3 times as long (?): https://github.com/jactor-rises/jactor-persistence/runs/4794532441?check_suite_focus=true

How can I set up an effective cache of dependencies and wrapper in a GitHub workflow?


Solution

  • I am experiencing problems with the cradle cache and have removed the cache and now using a gradle action for caching of dependencies:

    - name: Cache Gradle dependencies
      uses: actions/cache@v3
      with:
        path: ~/.gradle/caches
        key: gradle-${{ runner.os }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
        restore-keys: |
          gradle-${{ runner.os }}-