name: Cache Gradle

description: Cache Gradle wrappers and dependencies.

inputs:
  path:
    description: Paths to cache
    required: false
    default: |
      ~/.gradle/caches/modules-*
      ~/.gradle/caches/jars-*
      ~/.gradle/caches/build-cache-*
      ~/.gradle/wrapper
  cache-version:
    description: Additional cache version segment
    required: false
    default: v1

outputs:
  cache-hit:
    description: Whether an exact match was found for the cache key
    value: ${{ steps.cache.outputs.cache-hit }}

runs:
  using: "composite"
  steps:
    - id: cache
      name: Cache Gradle
      uses: actions/cache@v4
      with:
        path: ${{ inputs.path }}
        key: ${{ runner.os }}-gradle-${{ inputs.cache-version }}-${{ hashFiles('**/build.gradle', '**/settings.gradle', '**/gradle-wrapper.properties', '**/gradle.properties') }}
        restore-keys: |
          ${{ runner.os }}-gradle-${{ inputs.cache-version }}-
          ${{ runner.os }}-gradle-
