When a project is run (using wrapper command gradl...
# community-support
a
When a project is run (using wrapper command gradlew) from a certain environment say X, it fails to download the gradle wrapper. All I see are the .lck and .part files under the wrapper/dists. It was discovered that Anonymous GET requests from within the X environment to the artifactory instance(distributionURL) are not allowed and as a result fail everytime with an HTTP 401 error. It is now required that every GET request to this artifactory instance from within the environment X must be authenticated. I tried to lookup the documentation for authenticated gradle wrapper download. The documentation suggests using system properties for specifying http Basic auth credentials in gradle.properties or to embed the username:password in the ditributionUrl but neither seems to help. I still get 401 error. The error I am encountering is :
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 401 for URL: <the distributionUrl>
NOTE: I had earlier worked around this wrapper download issue by manually downloading the wrapper on my system(as download ), copying the distribution to the environment X and putting it in the distributionPath By doing so I was able to get the gradle wrapper being recognized and unzipped successfully. However the project build kept failing because the dependencies could no more be downloaded and threw HTTP 401 error. I was able to successfully build the project after passing credentials to my repository configurations. But the wrapper download issue still exists. UPDATE: I discovered that we had been carrying over a pretty old gradle-wrapper.jar. When I replaced it with a more recent one(6.8.3) it started working out of the box and the wrapper was getting downloaded. But I also noticed that for older gradle-wrapper.jar files the output result differed when downloading the corresponding Gradle wrapper: using the gradle-wrapper.jar for Gradle 2.5 : error was HTTP 401,
Copy code
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 401 for URL: <distribution-url-goes-here>
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
        at org.gradle.wrapper.Download.download(Download.java:44)
        at org.gradle.wrapper.Install$1.call(Install.java:59)
        at org.gradle.wrapper.Install$1.call(Install.java:46)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
        at org.gradle.wrapper.Install.createDist(Install.java:46)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:126)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
using the gradle-wrapper.jar for Gradle 3.5.1 and any later versions : PASSED I'm testing with above wrapper jars against the distributions Gradle 2.6(trying to upgrade a pretty old build)
Upon inspecting the gradle-wrapper jars the only relevant changes that I notice are introduction of ProxyAuthenticator class and the support for basic authentication(addBasicAuthentication method) in the org.gradle.wrapper.Download class. So far I'm good as my issue stands resolved. But I am still trying to understand why the wrapper download is no more throwing 401, given the fact that I am not providing any credentials either through http Basic auth credentials in gradle.properties or by embedding the username:password in the ditributionUrl Any help/guidance is appreciated.