Gradle wrapper fails to initialize

In an empty directory, I try to create the wrapper with:

gradle wrapper

Then I just run:

./gradlew --version

And I get the following error:

 % ./gradlew --version                                  [0]
Downloading https://services.gradle.org/distributions-snapshots/gradle-5.5.1-20190724234647+0000-bin.zip

Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle-dn.com/distributions-snapshots/gradle-5.5.1-20190724234647+0000-bin.zip
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1890)
	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:67)
	at org.gradle.wrapper.Download.download(Download.java:52)
	at org.gradle.wrapper.Install$1.call(Install.java:62)
	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:63)

I tried with 5.5.0, and I get the same error. Is there something wrong with my system?

Running gradle wrapper will generate the wrapper that will use a distribution of the same version. However, gradle-5.5.1-20190724234647+0000 is not a nightly version built by Gradle, so it can’t be found on the Gradle servers.

It seems likely that you’re using arch, which has built release versions from source, but with them labeled as a nightly snapshot. Therefore, your installed gradle binary from the package manager is broken.

You can solve it for this project by navigating to gradle/wrapper/gradle-wrapper.properties and removing the -snapshots and -20190724234647+0000 from the URL. To solve it for all projects going forward until the copy provided is fixed, you could uninstall Gradle from the package manager and manually install the actual release version binary of 5.5.1.

1 Like

I’m not sure it helps, but the Gradle wrapper version, created by the Wrapper task can be set in a wrapper block in the build configuration:

wrapper {
    gradleVersion  '5.5.1'
}

Though this requires the configuration per project.

1 Like

Got it, thanks!

It seems like I was unlucky because I tried to download 5.5.0 (which was failing), and I did not try 5.5.1 (which does work)…

Should I mark this post as resolved somehow?