Java: When does gradle-wrapper.jar change?

Viewed 294

I am trying to understand about gradle-wrapper.jar in git version control. I found the purpose of it on this question Purpose of gradle wrapper.jar in my libraries.

As binary files are not good to store in git if they are changing a lot, I assume gradle-wrapper.jar does not change very often, is this correct?

This also lead me to the question when does it change and why, is it when we update gradle version?

1 Answers

Short answer: You never need to upgrade the Gradle wrapper, unless you need a specific bugfix or feature of the wrapper itself (which is fairly rare).

Longer answer: The Gradle wrapper is extremely stable, in a sense.

That doesn't mean that no new versions are released. In fact the Gradle wrapper is released with each Gradle release.

But an ancient Gradle wrapper is usually not a problem, which is even explicitly mentioned in the docs:

Note that running the wrapper task once will update gradle-wrapper.properties only, but leave the wrapper itself in gradle-wrapper.jar untouched. This is usually fine as new versions of Gradle can be run even with ancient wrapper files. If you nevertheless want all the wrapper files to be completely up-to-date, you’ll need to run the wrapper task a second time.

What this means is that the Gradle wrapper is almost universally forward and backwards compatible (you can download a newer or older Gradle version with a given wrapper).

The only times you must upgrade the wrapper is if there is a bugfix or a feature in the wrapper that you absolutely must have.

For example the Gradle 6.0 release had 2 changes to the Gradle wrapper:

  • Wrapper reports download progress as percentage
  • Wrapper tries to recover from an invalid Gradle installation

So if you really want that progress update or you frequently suffer from invalid Gradle installations then you might want to upgrade your Gradle Wrapper past that version.

But very often projects can go many, many Gradle upgrade cycles without ever touching the gradle-wrapper.jar.

And that is, of course, by design. The Gradle designers know that storing frequently-changing binary files in a VCS (especially git) is not a good idea, so they have designed the wrapper to be as stable as possible by making it basically just a simple downloader/launcher for the real Gradle code.

Related