Why does gradle try to download itself when I execute "gradlew.bat run" even though I already have gradle installed and GRADLE_HOME set?

When I execute “gradlew.bat run” the first thing Gradle does it attempt to download itself. I have already successfully installed Gradle and even used the task “wrapper” to create the gradlew.bat script. I have GRADLE_HOME set as well (obviously otherwise “gradle -v” would not execute). I am using gradle version 2.1. In chapter 62.1 (http://www.gradle.org/docs/2.1/userguide/userguide_single.html#sec:configuration) of the Gradle User Guide it says “If you run Gradle with gradlew, the wrapper checks if a Gradle distribution for the wrapper is available. If so, it delegates to the gradle command of this distribution with all the arguments passed originally to the gradlew command. If it didn’t find a Gradle distribution, it will download it first.” My questions is why, since I have the appropriate version of Gradle installed, does it attempt to download itself? Please see the below for the details of my steps and setup.

C:\directories>dir

Volume in drive C has no label.

Volume Serial Number is ***

Directory of C:\directories

10/31/2014 10:41 AM

. 10/31/2014 10:41 AM

… 10/31/2014 10:40 AM

313 build.gradle 10/29/2014 08:42 AM

src

1 File(s)

313 bytes

3 Dir(s) 42,502,537,216 bytes free

C:\directories>gradle build :compileJava :processResources UP-TO-DATE :classes :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :check UP-TO-DATE :build

BUILD SUCCESSFUL

Total time: 6.066 secs C:\directories>gradle wrapper :wrapper

BUILD SUCCESSFUL

Total time: 5.173 secs C:\directories>dir

Volume in drive C has no label.

Volume Serial Number is ***

Directory of C:\directories

10/31/2014 10:41 AM

. 10/31/2014 10:41 AM

… 10/31/2014 10:41 AM

.gradle 10/31/2014 10:41 AM

build 10/31/2014 10:40 AM

313 build.gradle 10/31/2014 10:41 AM

gradle 10/31/2014 10:41 AM

5,080 gradlew 10/31/2014 10:41 AM

2,404 gradlew.bat 10/29/2014 08:42 AM

src

3 File(s)

7,797 bytes

6 Dir(s) 42,502,631,424 bytes free

C:\directories>gradle -v

------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------

Build time:

2014-09-08 10:40:39 UTC Build number: none Revision:

e6cf70745ac11fa943e19294d19a2c527a669a53

Groovy:

2.3.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:

1.8.0 (Oracle Corporation 25.0-b70) OS:

Windows 7 6.1 amd64

C:\directories>more build.gradle apply plugin: ‘java’

apply plugin: ‘application’ mainClassName = ‘hello.HelloWorld’

repositories {

mavenLocal()

mavenCentral() }

dependencies {

compile “joda-time:joda-time:2.2” }

jar {

baseName = ‘gs-gradle’

version = ‘0.1.0’ }

task wrapper(type: Wrapper) {

gradleVersion = ‘2.1’ }

C:\directories>gradlew.bat run Downloading https://services.gradle.org/distributions/gradle-2.1-bin.zip …Terminate batch job (Y/N)? y

C:\directories>

In short, the wrapper does’t take manual Gradle installations (which it has no control over) into account. Doing so would be more complicated and less reliable, without a significant gain in most cases.

Thanks for the quick reply. Not to be argumentative but it seems misleading that the documentation claims “If you run Gradle with gradlew, the wrapper checks if a Gradle distribution for the wrapper is available.” Is there no way to force gradle to at least attempt to use the existing installation? I will probably proceed allowing Gradle to download itself but I’m still curious. Especially since I literally built “gradlew.bat” with my existing gradle installation.

it seems misleading that the documentation claims […]

“Gradle distribution for the wrapper” doesn’t include manual installations.

Is there no way to force gradle to at least attempt to use the existing installation?

No, there is no way. You can control where Gradle is downloaded from in ‘gradle/wrapper/gradle-wrapper.properties’. For exampling, you could have it downloaded from your inhouse repository.