name: Gradle Setup
description: Setup Java and Gradle for KMP builds
inputs:
  cache_read_only:
    description: 'Whether Gradle cache is read-only'
    default: 'true'
  jdk_distribution:
    description: 'JDK distribution (temurin or jetbrains)'
    default: 'temurin'
  gradle_encryption_key:
    description: 'Encryption key for Gradle remote cache'
    required: false
runs:
  using: composite
  steps:
    - name: Copy CI Gradle properties
      shell: bash
      run: mkdir -p ~/.gradle && cp .github/ci-gradle.properties ~/.gradle/gradle.properties

    - name: Validate Gradle Wrapper
      uses: gradle/actions/wrapper-validation@v6

    - name: Set up JDK 21
      uses: actions/setup-java@v5
      with:
        java-version: '21'
        distribution: ${{ inputs.jdk_distribution }}
        token: ${{ github.token }}

    - name: Setup Gradle
      uses: gradle/actions/setup-gradle@v6
      with:
        cache-read-only: ${{ inputs.cache_read_only }}
        cache-encryption-key: ${{ inputs.gradle_encryption_key }}
        cache-cleanup: on-success
        add-job-summary: always
        gradle-home-cache-includes: |
          caches
          notifications
          ~/.m2/repository/org/robolectric