Skip to content

Gradle WrapperDownloader: move URL & sha into properties - #16521

Open
dsmiley wants to merge 2 commits into
apache:mainfrom
dsmiley:GradleWrapperDownloadConfig
Open

Gradle WrapperDownloader: move URL & sha into properties#16521
dsmiley wants to merge 2 commits into
apache:mainfrom
dsmiley:GradleWrapperDownloadConfig

Conversation

@dsmiley

@dsmiley dsmiley commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

And don't bother checking if the wrapper jar is out-of-date.

Goal: (1) Allow configuration of the wrapper location. (2) simpler; easier to maintain

Can replace #16483

And don't bother checking if the wrapper jar is out-of-date.
Comment thread gradlew

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.

I prefer not validating that an existing gradle wrapper matches the sha. Why bother checking this? If the user has a wrapper (whatever version/origin) that continues to work for them, let them continue to use it. If they don't like it anymore, they are free to remove/replace it.

Admittedly I was primarily motivated by the simplicity of using gradle-wrapper.properties for everything the downloader and the wrapper itself needs to know..

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.

The sha checking code is there because if you're switching branches (for example, the wrapper version changes), you want to update the wrapper jar too. It is a stricter check than just file timestamps.

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.

note: this pattern was flawed because the . can match a \

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.

Hmm.... What do you mean? It doesn't have a DOTALL flag, it should work just fine?

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.

The regexp is used with matcher.find(), which returns the LEFTMOST match. The non-greedy
.+? doesn't save you here, because . also matches / -- so the capture happily runs across path separators.

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 know what it does but I can't see how you're hitting a problem here - I suspect you're modifying this in place:

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

and your corporate url doesn't match the pattern, right? Sorry for being dim. Can you give me an example of when this pattern fails to work?

Anyway, this isn't a solution in the long term because this file is versioned... It'll be a nightmare for you to have to adjust it everywhere.

I've gone through gradle's docs, issues and the wrapper code and I wonder how anybody in a corporate environment is solving the problem of auto-gradle-distro-installation (wrapper jar aside). There seem to be only two options that I see:

  1. use http proxy props and a proxy server to redirect gradle's "official" URLs to another location; this is tricky with https certs,
  2. store the binary distribution with the code (yes, it's possible). This dodges the download problem entirely.

It's interesting to me that there seems to be no way of redirecting these URLs "dynamically" -- seems like people behind firewalls need to install gradle manually (?). I guess adding a property to download something from arbitrary locations may be perceived as a security issue, don't know.

Looking at what's inside the gradle wrapper code, we may indeed try to simulate the same runtime behavior (using much less code) but skipping gradle-wrapper.jar entirely will break higher-level tools that depend on it (like intellij) so I think it needs to be there.

# Read by Lucene's WrapperDownloader (not by the actual wrapper) to bootstrap gradle-wrapper.jar.
wrapperSha256=497c8c2a7e5031f6aa847f88104aa80a93532ec32ee17bdb8d1d2f67a194a9c7
wrapperUrl=https\://raw.githubusercontent.com/gradle/gradle/v9.6.1/gradle/wrapper/gradle-wrapper.jar
# To self download, try %> curl -Lo gradle/wrapper/gradle-wrapper.jar <wrapperUrl> (from the repo root)

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.

this comment is helpful to anyone who wants to download it themselves (me). I have proxy env vars.

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 wouldn't put anything in here. This is controlled by gradle - when you update the wrapper, it'll likely get overwritten and people use llms more and more for such stuff... Likely to break in my opinion.

@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 am not convinced this is a good change, I tried to add my comments where they're relevant. In short: I wouldn't piggyback our own stuff in gradle.properties and I think the sha checksum makes sense here to ensure consistency when switching branches back and forth between versions.

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

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

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.

Hmm.... What do you mean? It doesn't have a DOTALL flag, it should work just fine?

# Read by Lucene's WrapperDownloader (not by the actual wrapper) to bootstrap gradle-wrapper.jar.
wrapperSha256=497c8c2a7e5031f6aa847f88104aa80a93532ec32ee17bdb8d1d2f67a194a9c7
wrapperUrl=https\://raw.githubusercontent.com/gradle/gradle/v9.6.1/gradle/wrapper/gradle-wrapper.jar
# To self download, try %> curl -Lo gradle/wrapper/gradle-wrapper.jar <wrapperUrl> (from the repo root)

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 wouldn't put anything in here. This is controlled by gradle - when you update the wrapper, it'll likely get overwritten and people use llms more and more for such stuff... Likely to break in my opinion.

Comment thread gradlew

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.

The sha checking code is there because if you're switching branches (for example, the wrapper version changes), you want to update the wrapper jar too. It is a stricter check than just file timestamps.

@dweiss

dweiss commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Would it be sufficient for your corporate environment if:

  1. we modified the regexp to be more strict and match version number only.
  2. perhaps allow passing gradle wrapper "location template" via environment variable, for example?

@dsmiley

dsmiley commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

A "location template" sounds more complicated than needed. Why not simply provide the wrapper location (URL) itself?

@dsmiley

dsmiley commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

we don't need to change the gradle wrapper any more often than we move to a major version, and even that is unnecessary.

@dweiss

dweiss commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

we don't need to change the gradle wrapper any more often than we move to a major version, and even that is unnecessary.

True. But this doesn't solve the problem of hardcoded gradle distribution URL - this is in wrapper.properties and it's a versioned file (see my other comment).

@dweiss

dweiss commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

I've done some experiments with replicating what gradle-wrapper does (like you did, David) and I think it's a better way to go - have a custom class to download and install a gradle distribution. It's really not that much code and it's self-contained. Give me some time to test it out though and perhaps polish machine-generated experiments.

@dweiss

dweiss commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Here is my take on this: #16543

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