Skip to content

Custom GradleWrapper - #16483

Draft
dsmiley wants to merge 2 commits into
apache:mainfrom
dsmiley:CustomGradleWrapper
Draft

Custom GradleWrapper#16483
dsmiley wants to merge 2 commits into
apache:mainfrom
dsmiley:CustomGradleWrapper

Conversation

@dsmiley

@dsmiley dsmiley commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I got frustrated with the gradle wrapper situation. The fact that we went through all this trouble here with a custom downloader -- all to download another tiny program (the actual gradle wrapper) to basically just download and run Gradle ... seems a bit silly, no?

So I had an idea and filed it with the Gradle project to offer the wrapper in source form.. Maybe they won't implement the idea but nonetheless we are certainly empowered to do so. It's not hard!

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably no more code involved in doing this than what we have today. I like that it's simpler; removing some entanglements in the shell & GHA yml.

Comment thread gradle/wrapper/GradleWrapper.java Outdated
Comment thread gradle/wrapper/GradleWrapper.java
Execute gradle in the same JVM.
Support the gradle-wrapper.jar if present.
Only include basic/used gradle-wrapper.properties

@dweiss dweiss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea. I'm not sure what the original gradle wrapper does (or will do in the future) though - it'd be good to move the burden of maintaining it to gradle itself... but I don't have high hopes they'll be interested.

What was the source of your frustration with the previous downloader? It didn't work? I never had any problem with it, even when switching branches etc.

Comment thread gradlew.bat
Comment on lines +98 to +99
@rem No staleness check: if you edit GradleWrapper.java, delete %GRADLE_WRAPPER_CACHE% to force
@rem a recompile (this file changes rarely, so keeping this simple is worth that manual step).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's going to be trouble on Windows if the wrapper is updated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be some powershell solutions to check the 'if newer' condition but they're rather hairy. Don't know if there's any other way but right now I think it's going to be trappy for WIndows users.

throw new IOException("Wrapper property file not found: " + wrapperProperties);
}

Pattern versionPattern = Pattern.compile("gradle-(?<version>.+?)-bin.zip");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the source of your frustration with the previous downloader? It didn't work? I never had any problem with it, even when switching branches etc.

Our downloader's regexp didn't like my corporate URL to our local gradle location. The "." in there could match anything, even a forward slash.

But even fixing that didn't resolve the matter since my corporate env can't access internet sites like 'raw.githubusercontent.com`. Ugh! So in a fit of frustration, I went on this path. Downloading a downloader is insanity. Just download the final thing already!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it can download gradle but can't download the wrapper? Maybe we could just modify the location the wrapper is downloaded from so that it's the same as gradle distribution?

I don't oppose the change but it breaks Windows, for example - the up-to-date check there is gone and switching between different versions won't work.

Comment thread .gitignore
Comment on lines -8 to -10
# Ignore gradle wrapper jar.
gradle/wrapper/gradle-wrapper.jar

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed from gitignore yet the batch scripts clearly seem to support the presence of gradle wrapper (?). I also wonder how IDEs are going to react to the missing wrapper file...

Comment on lines +87 to +91
// Doesn't need to match Gradle's own MD5-based cache hash scheme (PathAssembler) -- this is
// an independent cache, keyed only well enough to dedupe by exact distributionUrl.
String hash = sha256Hex(urlStr).substring(0, 16);
Path installRoot =
gradleUserHome.resolve("wrapper").resolve("dists").resolve(baseName).resolve(hash);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a global lock in the original wrapper here and it's for a reason - if somebody starts multiple builds in parallel it can potentially leave an inconsistent state of a global "cached" install. I'm also not sure we can reuse the same directory as the official distribution... not sure what they do to these files/ directories. Maybe it'd be good not to interfere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants