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?
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...
UPDATE:
In case of gradle cache is not found check /gradlew script and /gradle/wrapper directory, they should be committed also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With