gradle / actions

A collection of GitHub Actions to accelerate your Gradle Builds on GitHub
https://github.com/marketplace/actions/build-with-gradle
MIT License
126 stars 28 forks source link

gradle/actions/setup-gradle: 'wrapper' gradle-version does not use Gradle wrapper version #273

Open Virtlink opened 4 days ago

Virtlink commented 4 days ago

I use the gradle/actions/setup-gradle task with a version matrix gradle-version: ['wrapper', '7.6.4', '8.8']. For the 'wrapper' value, I expected it to use the gradlew wrapper version of Gradle (8.6 in my case, as documented). Instead, it uses a seemingly random (latest?) version of Gradle (Gradle 8.8 in my case).

For the explicitly specified versions 7.6.4 and 8.8, it works correctly, downloading and setting up that Gradle version. The subsequent call togradle build executes with the intended Gradle version. However, for the 'wrapper' version of Gradle, which is Gradle 8.6 in my project, it instead uses Gradle 8.8.

This is the relevant part of my workflow:

jobs:
  build:
    strategy:
      matrix:
        gradle-version: ['wrapper', '7.6.4', '8.8']
    steps:
      # ...
      - name: "Setup Gradle ${{ matrix.gradle-version }}"
        uses: gradle/actions/setup-gradle@v3
        with:
          gradle-version: ${{ matrix.gradle-version }}
          build-scan-publish: true
          build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
          build-scan-terms-of-use-agree: "yes"
      - name: 'Build'
        run: |
          gradle build
bigdaz commented 2 days ago

Thanks for reporting. You're correct that the wrapper version keyword doesn't work using setup-gradle with a separate build step. This feature is a leftover from the gradle-build-action which provided a arguments parameter to directly execute Gradle.

Using gradle-version: wrapper with setup-gradle doesn't make sense, since it doesn't download any Gradle version and it doesn't (cannot) update the path so that gradle == ./gradlew.

In order to use a matrix to execute with multiple Gradle versions (including the wrapper), you'll need to do something like:

jobs:
  build:
    strategy:
      matrix:
        gradle-version: ['wrapper', '7.6.4', '8.8']
        gradle-command: ['gradle']
        include:
        - gradle-version: 'wrapper'
          gradle-command: './gradlew'

    steps:
      # ...
      - name: "Setup Gradle ${{ matrix.gradle-version }}"
        uses: gradle/actions/setup-gradle@v3
        with:
          gradle-version: ${{ matrix.gradle-version }}
          build-scan-publish: true
          build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
          build-scan-terms-of-use-agree: "yes"
      - name: 'Build'
        run: |
          ${{matrix.gradle-command}} build

This isn't ideal, but it should provide a workaround. I'll leave this issue open pending a better solution (if possible).

Virtlink commented 2 days ago

Thank you for the workaround, I didn't know about the matrix.include option. I will try this soon.

I don't know how setup-gradle works internally, but apparently it can update the PATH to include the downloaded gradle. So for a wrapper it could instead inject a small script named gradle that just calls ./gradlew in the current directory.