Home > Net >  how to reuse gradle cache in GitHub workflow
how to reuse gradle cache in GitHub workflow

Time:01-19

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?

CodePudding user response:

Instead of manually configure caching of gradle, use an action which is provided. From my workflow file now:

      - uses: actions/setup-java@v2
        with:
          distribution: temurin
          java-version: 17
          cache: gradle

the setup-java-action will cache for gradle and maven so there is no need to manual set up caching...

  •  Tags:  
  • Related