Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying gradle-version: 'wrapper' does not cause Gradle wrapper to be used #273

Open
Virtlink opened this issue Jul 1, 2024 · 3 comments
Labels
bug Something isn't working in:setup-gradle

Comments

@Virtlink
Copy link

Virtlink commented Jul 1, 2024

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
Virtlink added a commit to metaborg/actions that referenced this issue Jul 1, 2024
Virtlink added a commit to metaborg/actions that referenced this issue Jul 1, 2024
@bigdaz
Copy link
Member

bigdaz commented Jul 2, 2024

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
Copy link
Author

Virtlink commented Jul 3, 2024

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.

@bigdaz
Copy link
Member

bigdaz commented Jul 5, 2024

for a wrapper it could instead inject a small script named gradle that just calls ./gradlew in the current directory.

Yes I thought of that too. I'll see if that would work.

@bigdaz bigdaz added enhancement New feature or request in:setup-gradle bug Something isn't working and removed enhancement New feature or request labels Jul 15, 2024
@bigdaz bigdaz added this to the v4.0.0 milestone Jul 22, 2024
@bigdaz bigdaz removed this from the v4.0.0 milestone Jul 31, 2024
@bigdaz bigdaz changed the title gradle/actions/setup-gradle: 'wrapper' gradle-version does not use Gradle wrapper version Specifying gradle-version: 'wrapper' does not use Gradle wrapper version Jul 31, 2024
@bigdaz bigdaz changed the title Specifying gradle-version: 'wrapper' does not use Gradle wrapper version Specifying gradle-version: 'wrapper' does not cause Gradle wrapper to be used Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in:setup-gradle
Projects
None yet
Development

No branches or pull requests

2 participants