Skip to content

Honoring configured networkTimeout when calling ./gradle wrapper#14043

Merged
kbukum1 merged 3 commits into
dependabot:mainfrom
gmazzo:gradle-wrapper-network-timeout-fix
Feb 4, 2026
Merged

Honoring configured networkTimeout when calling ./gradle wrapper#14043
kbukum1 merged 3 commits into
dependabot:mainfrom
gmazzo:gradle-wrapper-network-timeout-fix

Conversation

@gmazzo
Copy link
Copy Markdown
Contributor

@gmazzo gmazzo commented Jan 29, 2026

What are you trying to accomplish?

Fixes #14027 by workaround gradle/gradle#36172, by reading networkTimeout property from gradle-wrapper.properties and passing it as --network-timeout when calling ./gradlew wrapper.

Anything you want to highlight for special attention from reviewers?

As I commented at #14024 (comment), I don't think we should be patching Gradle's defects. But in case you decide to move forward, this should be a way to do it.

How will you know you've accomplished your goal?

Tests and smoke tests will cover it

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@github-actions github-actions Bot added the L: java:gradle Maven packages via Gradle label Jan 29, 2026
@gmazzo gmazzo force-pushed the gradle-wrapper-network-timeout-fix branch 2 times, most recently from 9553f04 to 6fa2d2f Compare January 29, 2026 11:01
sig { params(properties_file: T.any(Pathname, String)).returns(T.nilable(String)) }
def get_validate_distribution_url_option(properties_file)
return nil unless File.exist?(properties_file)
# For the same reason, we apply the same for `--network-timeout`.
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.

Let's add the right context here please. It is not exactly the same reason.

Hopefully we can merge #14037 first, or you can cherry-pick my commit and we merge it as a single change; It does not matter to me as long as the context is captured

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.

If we follow the pattern in #14037, we can add it as we define the argument rather that in the method docs

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.

Just solved conflicts and added some wording for it. Feel free to make it better ;)

# For the same reason, we apply the same for `--network-timeout`.
sig { params(properties_file: T.any(Pathname, String)).returns(T::Array[T.nilable(String)]) }
def read_wrapper_options(properties_file)
return [nil, nil] unless File.exist?(properties_file)
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 think that this check should not be here, instead, it should be before this method is called

If there is no property file all the way to this context, the subsequent logic should not run at all

To be fair, based on what I currently see in the code, I don't even think that's possible either

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'd prefer to keep it in here to be honest. If, for whatever reason, the file is not there, then there are no values to read, so it's the same as if they are not present at all in the .properties file. It keeps the logic encapsulated.

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.

In what situation can the property file not exist and get to this context? Maybe I am missing something

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 reason I ask is because extra error handling does not help if it can never happen. It does not hurt in terms of error handling, it is just dead code

But maybe I am missing something

env = { "JAVA_OPTS" => proxy_args.join(" ") } # set proxy for gradle execution

command_parts = %w(--no-daemon --stacktrace) + command_args(target_requirements, network_timeout)
command = Shellwords.join([has_local_script ? "./gradlew" : "gradle"] + command_parts)
Copy link
Copy Markdown
Contributor

@yeikel yeikel Jan 29, 2026

Choose a reason for hiding this comment

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

Can we remove this workaround in this change or in a future change?

I am honestly not too sure this can happen. From what I remember, this was added because of fears that users may not commit the Unix variant, but honestly, I am not too sure if we should actually even do this. Of all the hacks, this is the one I regret the most because Dependabot works in Unix and we can set that as an expectation

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.

No, this was because:

  1. It could be possible that ./gradlew script was altered, not working (without +x permission) or even not existing at all, and that will dependabot to fail.
  2. Or the gradle-wrapper.jar is corrupted, compiled for an incompatible java version, et.

So, panic condition, if updating with the current wrapper helper code fails, we'll try with system's native gradle instalation before giving up.

Actually, one of the smoke tests is validating this scenario.

Copy link
Copy Markdown
Contributor

@yeikel yeikel Jan 29, 2026

Choose a reason for hiding this comment

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

Sorry, I meant the has_local_script check. I understand the fallback mechanism, what I don't understand is when has_local_script can be false

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.

We don't know the structure of a project. Is possible they do have a gradle/gradle-wrapper.properties file, but for some reason (for instance, they only support Windows) they have decided not to commit the ./gradlew script.

That's the thing, we don't know. This is more to have a robust code prepared for any kind of scenario (that we can predict, without entering too much complexity).

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.

Thanks, I think that we should log this behavior in a follow up change. Just for user's awareness.

@yeikel
Copy link
Copy Markdown
Contributor

yeikel commented Jan 29, 2026

This change closes #14026

Comment thread gradle/lib/dependabot/gradle/file_updater/wrapper_updater.rb Outdated
@gmazzo gmazzo force-pushed the gradle-wrapper-network-timeout-fix branch 4 times, most recently from 17f0f51 to 3d826d2 Compare January 30, 2026 09:06
Comment thread gradle/lib/dependabot/gradle/file_updater/wrapper_updater.rb Outdated
@yeikel
Copy link
Copy Markdown
Contributor

yeikel commented Jan 30, 2026

Changes look good to me. Thanks for the effort

@kbukum1 Please review when you are ready. Also see the discussion as to why I believe that we should still do this even if it feels that Gradle should do it

@gmazzo gmazzo marked this pull request as ready for review February 1, 2026 19:39
@gmazzo gmazzo requested a review from a team as a code owner February 1, 2026 19:39
its(:content) do
expected_command = %W(
./gradlew --no-daemon --stacktrace wrapper --gradle-version 9.0.0 --no-validate-url
--network-timeout 10000
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.

As this is the default value, can we please create a test to ensure that other than the default is respected? Maybe an integration test?

@kbukum1
Copy link
Copy Markdown
Contributor

kbukum1 commented Feb 2, 2026

Changes look good to me. Thanks for the effort

@kbukum1 Please review when you are ready. Also see the discussion as to why I believe that we should still do this even if it feels that Gradle should do it

@gmazzo , thanks for the effort. I did review it roughly. I will review again later. Currently there are issues on actions and pipeline is failing. I will review later and most probably approve since I see you guys did great job went on every detail. @yeikel thank you for all reviews and questions. It helps a lot.

@kbukum1 kbukum1 self-assigned this Feb 2, 2026
@kbukum1 kbukum1 moved this to On Hold in Dependabot Feb 2, 2026
@kbukum1 kbukum1 force-pushed the gradle-wrapper-network-timeout-fix branch from c47aa13 to 15dabae Compare February 4, 2026 03:16
@kbukum1 kbukum1 moved this from On Hold to In Progress in Dependabot Feb 4, 2026
@kbukum1 kbukum1 force-pushed the gradle-wrapper-network-timeout-fix branch from 15dabae to 2a4d4d1 Compare February 4, 2026 03:49
@JamieMagee JamieMagee force-pushed the gradle-wrapper-network-timeout-fix branch from 2a4d4d1 to 2dd6bf3 Compare February 4, 2026 04:02
@yeikel
Copy link
Copy Markdown
Contributor

yeikel commented Feb 4, 2026

The build failure seems like a temporary downtime. Retrying the build should fix it

@kbukum1 kbukum1 merged commit cd91cb5 into dependabot:main Feb 4, 2026
93 of 94 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Dependabot Feb 4, 2026
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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Gradle wrapper permissions are downgraded during upgrade

3 participants