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

Support upgrading Gradle itself #7124

Open
1 task done
airsquared opened this issue Apr 20, 2023 · 7 comments
Open
1 task done

Support upgrading Gradle itself #7124

airsquared opened this issue Apr 20, 2023 · 7 comments
Labels
L: java:gradle Maven packages via Gradle T: feature-request Requests for new features

Comments

@airsquared
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Feature description

Gradle projects store which version of Gradle to use in the /gradle/wrapper/gradle-wrapper.properties file, and frequently forget to upgrade it.

A gradle-wrapper.properties may have various entries in any order but only the distributionUrl entry is relevant to the versioning and looks something like this:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip

To upgrade the gradle version, you only need to update the string in between gradle- and -bin. For example to upgrade from Gradle 8.1 to 9.0.1 as above, the line needs to be changed to:

distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.1-bin.zip

It may end in either "-bin" or "-all" depending on which kind of distribution the user picked, but doesn't make a difference for upgrading the version.

The latest release of Gradle can be obtained programmatically from Gradle's GitHub releases.

@airsquared airsquared added the T: feature-request Requests for new features label Apr 20, 2023
@jeffwidman jeffwidman added the L: java:gradle Maven packages via Gradle label Apr 20, 2023
@jeffwidman
Copy link
Member

Thanks for the detailed description.

Does native Gradle have a feature to update this line itself? Ie, if we leveraged more native Gradle tooling, would it make it easier to solve this as a byproduct?

An alternative approach that'd make it easy to solve this is probably:

@airsquared
Copy link
Author

airsquared commented Apr 20, 2023

There is also a command to upgrade which does the same thing:

./gradlew wrapper --gradle-version=9.0.1

I'm not sure if this is also available with the tooling API, but that may complicate things more compared to just editing a string in the properties file.

@yeikel
Copy link
Contributor

yeikel commented Apr 21, 2023

I think that this would be a "new ecosystem" as we would be entering the business of upgrading a different type of files (wrapper files)

@hfhbd
Copy link
Contributor

hfhbd commented May 2, 2023

See also: #2223

@Thunderforge
Copy link

Thunderforge commented May 31, 2023

Sometimes newer versions of a Gradle wrapper also make changes to the following files (which are used for downloading the wrapper executable):

  • ./gradlew (shell script)
  • ./gradlew.bat
  • ./gradle/wrapper/gradle-wrapper.jar

We could naively edit the value in ./gradle/wrapper/gradle-wrapper.properties, but then these other files wouldn't be updated. Gradle commands will still work properly under the requested version, but these scripts that download the wrapper executable won't have the latest bug fixes and optimizations.

If we could run ./gradlew wrapper --gradle-version=9.0.1, that would be ideal since it would update all four files.

(Also as a personal thing, I would love it if it would also ensure that ./gradlew has chmod +x so that Mac and Linux users can use it even if a Windows user generated it, but that might be out of scope).

@joffrey-bion
Copy link

joffrey-bion commented Jul 17, 2023

That would indeed be great! Note that the proposed command is not complete. It's often desirable to use the new version's checksum as well, which means providing the --gradle-distribution-sha256-sum option in addition to --gradle-version.

For more info about the possibilities for this, please have a look at this GitHub Action:
https://github.com/gradle-update/update-gradle-wrapper-action

Sometimes newer versions of a Gradle wrapper also make changes to the following files

Because of this, it's usually useful to run the ./gradlew wrapper command twice:

  • the first time sets the version in the properties file, but is still doing this by running the old version of Gradle
  • the second time, the actual new Gradle version is downloaded and run (because of the properties file update), so it updates the related wrapper scripts and jar files, which can be part of the same "update Gradle wrapper" PR

I think that this would be a "new ecosystem" as we would be entering the business of upgrading a different type of files (wrapper files)

I agree with this too!

Also as a personal thing, I would love it if it would also ensure that ./gradlew has chmod +x so that Mac and Linux users can use it even if a Windows user generated it, but that might be out of scope

That should just be done the first time you generate the files. Or if the first person committing gradlew forgot to do it, it's easily fixable by just running git update-index --chmod=+x gradlew and then committing and pushing the change (it also has to be done only once). I don't think there is any point in dependabot to handle one-time setups (the point is to maintain things up-to-date, not to preconfigure things). AFAIK, subsequently updating the wrapper normally should keep the executable flag so I don't think Dependabot would mess this up.

@MGaetan89
Copy link

There is also a command to upgrade which does the same thing:

./gradlew wrapper --gradle-version=9.0.1

I'm not sure if this is also available with the tooling API, but that may complicate things more compared to just editing a string in the properties file.

And since Gradle 8.1, it's possible to use a label, instead of a specific version, for example:

./gradlew wrapper --gradle-version latest

https://docs.gradle.org/8.1/release-notes.html#gradle-wrapper-introduces-labels-for-selecting-the-version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: java:gradle Maven packages via Gradle T: feature-request Requests for new features
Projects
None yet
Development

No branches or pull requests

7 participants