Skip to content

Gradle wrapper doesn't respect HTTP 301 and 302 redirects to HTTPS #6033

@reegnz

Description

@reegnz

Expected Behavior

If distribution URL returns a 301 or 302 status code with a Location header, the wrapper should retry the request with the URL returned in the Location header.
Redirects should be followed recursively (until a reasonable upper bound in the count of redirects is reached).

Current Behavior

If the configured distribution url returns a 301 or 302 the wrapper fails:

Downloading http://my-local-dist-mirror.example.com/gradle-4.8.1-all.zip

Could not unzip C:\Users\reegnz\.gradle\wrapper\dists\gradle-4.8.1-all\2fm1bdco840fg368obqx86w8g\gradle-4.8.1-all.zip to C:\Users\reegnz\.gradle\wrapper\dists\gradle-4.8.1-all\2fm1bdco840fg368obqx86w8g.
Reason: error in opening zip file
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:225)
        at java.util.zip.ZipFile.<init>(ZipFile.java:155)
        at java.util.zip.ZipFile.<init>(ZipFile.java:169)
        at org.gradle.wrapper.Install.unzip(Install.java:218)
        at org.gradle.wrapper.Install.access$600(Install.java:27)
        at org.gradle.wrapper.Install$1.call(Install.java:75)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

Context

We had the distribution available through http in the past.
Recently we changed the server to redirect all requests on port 80 to try again with https.

This broke the gradle wrapper downloads in our CI.

Steps to Reproduce (for bugs)

  1. Have a webserver that redirects from a specific url to the gradle wrapper location
  2. Configure gradle wrapper with that url

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed:not-fixedIndicates the issue was not fixed and is not planned to be

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions