106

I'm trying to build a gradle project with gradle-wrapper (gradlew).

When I build with ./gradlew build, it outputs text

Downloading http://services.gradle.org/distributions/gradle-1.11-bin.zip

And I already got gradle-1.11-bin.zip downloaded separately and I don't want to be downloading it again when I build.

So, where shall I put gradle-1.11-bin.zip in my project or system so that I don't have to download again?

gradle/wrapper/gradle-wrapper.properties is as following.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip

And I've tried copying gradle-1.11-bin.zip into gradle/wrapper/dists which didn't solve the problem.

TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125

10 Answers10

135

From gradle-wrapper documentation, I found in section 61.1. Configuration

If you don't want any download to happen when your project is build via gradlew, simply add the Gradle distribution zip to your version control at the location specified by your wrapper configuration. A relative URL is supported - you can specify a distribution file relative to the location of gradle-wrapper.properties file.

So, I changed distributionUrl property in gradle/wrapper/gradle-wrapper.properties to

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-1.11-bin.zip

Then, I made a copy of gradle-1.11-bin.zip in gradle/wrapper/.

Then, ./gradlew build downloaded local copy of zip and built the project.


Here's a real-world example:

mkdir -p $HOME/dev
cd $HOME/dev
git clone https://github.com/oss-review-toolkit/ort
cd ort/gradle/wrapper
wget https://services.gradle.org/distributions/gradle-7.5.1-bin.zip
sed -i 's/distributionUrl=.*/distributionUrl=gradle-7.5.1-bin.zip/' gradle-wrapper.properties 
cd ../..
./gradlew installDist
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
  • 11
    This misses a main point of the wrapper, which is that Gradle is downloaded and installed automatically for all build users. If you prefer to use a local installation, put it on your PATH and invoke `gradle` rather than `gradlew`. – Peter Niederwieser Apr 07 '14 at 06:59
  • 51
    This is a big deal if you need to send software to somebody who doesn't have Internet access. Yes, that's something that really happens; there are computers that aren't connected to the Internet. – Chris Jones Sep 18 '15 at 01:15
  • 4
    This is very important for Enterprise usage. Our build server is not allowed to access the internet. All dependencies are fetched from Nexus, but the wrapper always was a problem and stopped the adoption of gradle. A central installation could solve it but you would need all possible versions of gradle since every build could use it specific version. However the best solution would be to fetch the zip also from nexus, but this change request was refused. – ChrLipp Dec 05 '16 at 14:32
  • Is there a way to use environment variables to define the gradle path that is located inside the Android Studio folder? for example define a relative path for: `..\android-studio\gradle\gradle-3.3-all.zip` – ir-tech Apr 21 '17 at 21:01
  • // Do not use android 8 as it will keep downloading grade distribution use grade 7 ionic cordova platform add android@8.0.0 – Anand_5050 Sep 15 '19 at 08:37
  • This was a life-saver. I kept getting SSL errors saying that the file couldn't be downloaded. This workaround let me complete my build. Thanks! – TheRealMikeD May 04 '22 at 20:14
57

Modifty the gradle/gradle-wrapper.properties

Windows:

distributionUrl=file\:/d:/gradle-2.2.1-all.zip

linux:

distributionUrl=file\:/tmp/gradle-2.2.1-all.zip
wcc526
  • 3,915
  • 2
  • 31
  • 29
  • 2
    Usually, I use the windows version of Android Studio but sometimes I open my projects in a Linux operating system. Is it possible to define `distributionUrl` in such a way that Gradle ZIP package be accessible on both OS without changing `distributionUrl` value? – ir-tech Apr 21 '17 at 20:51
  • 2
    @ir-tech, you can use relative path, like file\:///../lib/gradle-2.2.1-all.zip – AaA Jul 06 '17 at 09:35
  • // Do not use android 8 as it will keep downloading grade distribution use grade 7 ionic cordova platform add android@8.0.0 // This will run ionic cordova platform add android@~7.1.1 --save Then run below and this time it should get success( Worked for me) ionic cordova build android – Anand_5050 Sep 15 '19 at 08:37
  • This did not work for me. Just omitting the 'file' stuff worked fine though: `distributionUrl=../lib/gradle-2.2.1-all.zip`. The path is relative to the `/gradle/wrapper/` folder. – user136036 Feb 28 '21 at 11:21
  • Nice~ Saved my life. – JohnWatsonDev Mar 05 '21 at 10:48
28

Just drag downloaded gradle file in your browser address bar and then copy address from address bar and change gradle/wrapper/gradle-wrapper.properties as following:

distributionUrl=ADDRESS THAT COPY FROM YOUR BROWSER

example:

distributionUrl=file:///E:/gradle/gradle-4.1-all.zip

or you can copy gradle.zip file to wrapper folder then use relative path:

distributionUrl=gradle.zip
Ahmad Dehnavi
  • 1,483
  • 1
  • 17
  • 20
  • Not working. distributionUrl get auto correct to https\://services.gradle.org/distributions/gradle-4.10.3-all.zip on ionic cordova build android – Anand_5050 Sep 15 '19 at 08:26
9

This is what I did to avoid editing all gradle wrapper for current and future projects.

  • Locate your gradle-wrapper.properties in your project folder (eg. ./gradle/wrapper/gradle-wrapper.properties)
  • open the file with a text editor like Sublime Text to locate the distributionUrl line (eg. distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-bin.zip

The gradle binary archive needed is gradle-2.10-bin.zip. Another version is gradle-2.10-all.zip that includes everything including source code and documentation.

Please note each project ships with different versions of gradle distributions and you can change the version to the one you have (gradle-x.xx-XXX.zip) that include the binary. (eg. gradle-2.11-bin.zip | gradle-2.11-all.zip ).

Execute gradlew.bat on window or gradle on linux to start the wrapper to build the project.

It will begin downloading the gradle-2.10-bin.zip to the .gradle\wrapper\dists in your home directory (eg.C:\Users\Sojimaxi\.gradle\wrapper\dists\gradle-2.10-bin). This download happens just once for each specified gradle version.

If you already downloaded the archive before you can terminate the download using Ctrl+C

Go into the gradle download location C:\Users\Sojimaxi\.gradle\wrapper\dists\gradle-2.10-all\78v82fsf226usgvgh7q2ptcvif copy your own copy of gradle-2.10-bin.zip into that directory then delete the gradle-2.10-all.zip.part in that directory.

That's all. Go back to your project directory to execute gradlew.bat and it will use your local copy instead of downloading a new one.

mx0
  • 6,445
  • 12
  • 49
  • 54
Sojimaxi
  • 485
  • 1
  • 10
  • 17
4

This solution didn't work for me but help me to get the right way so if you want install gradle offline follow these steps:

1- at your project under gradle directory open this file (gradle-wrapper.properties)

2- at last line you will find the gradle version, download that version or copy the file from another pc

distributionUrl=http\://services.gradle.org/distributions/gradle-3.3-bin.zip

Download Link will be like this: http://services.gradle.org/distributions/gradle-3.3-bin.zip

3- open this location C:\Users\userName.gradle\wrapper\dists\gradle-3.3-all and ensure that is only one folder (the name doesn’t matter it different at devices) if there any other folders delete all of them and press gradle sync on android studio which will generate another folder automatic with a random name.

4- open that folder and ensure that has only the last two files in the screenshot.

5- move the zip file that you downloaded into that folder

6- press sync gradle on android studio again suppose that gradle will work fine.

enter image description here

Mohamed ElSawaf
  • 229
  • 2
  • 8
2

I found another easiest way to do this just started my XAMPP server and then made a folder gradle inside htdocs. I added the zipped file gradle-4.4-all.zip inside that folder. Changed the distribution url to distributionUrl=http\://localhost/gradle/gradle-4.4-all.zip I restarted android and the syncing completed without any issue.

Amit Ray
  • 3,445
  • 2
  • 19
  • 35
1

copy your path wher you put the file gradle-5.0-rc-5-bin.zip example: path C:/My doc/tools

if you have some spaces in your path change it with %20

file:///C:/My%20doc/tools/gradle-5.0-rc-5-bin.zip

and execute the command:

$ gradlew wrapper --gradle-version 5.0-rc-5
alepuzio
  • 1,382
  • 2
  • 28
  • 38
Aek Dadi
  • 11
  • 1
  • 1
0

I download to

C:\data\Setup\Development\Gradle 2.11\gradle-2.11-all.zip

inside Eclipse, I declare: enter image description here


Then I create new Gradle project (with wrapper) very fast, no need download. (Easy more than this solution)

Community
  • 1
  • 1
Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • ya, it is speedy. beacuse unlike other answers, it uses the gradle available in the system than downloading a gradle distribution via http or file protocol, unzipping and executing it. – Banee Ishaque K Jul 12 '17 at 13:21
  • In my case, firstly i geos with @edward anderson's method. then switched to wcc526's method ( it is a modification of TheKojuEffect's method), atlast to this method. – Banee Ishaque K Jul 12 '17 at 13:25
  • But now i have a problem with this method. i am using gradle-4.0-rc-3 on my system. but that version deosn't work latest android studio ( i think latest version is 3.0-alpha6, but i have 3.0-alpha5) - it always errors by latest supported gradle version is gradle-4.0-milestone-1, your version is 4.0-rc-3. i have to downgrade my system gradle to 4.0-milestone-1 or always use gradle wrapper with android studio projects. is there any workaround for this problem? – Banee Ishaque K Jul 12 '17 at 13:30
  • Just making gradle work in your IDE but not the gradle command line is a great way to not be able to use or trust your build tool to do anything. You should only try to make the IDE work _AFTER_ you verify the command line build is successful. Doing it the other way around is a great way to lose hours and days of your lives trying to figure out why things break randomly and differently on yours and everyone else's machine... – Ajax Dec 16 '18 at 11:02
0

create local server to mock https download(maybe a little complex),but it work
1. install tomcat then unzip and exec E:\apache-tomcat-8.5.4\bin\startup.bat

2.put gradle-2.14.1-all.zip to E:\apache-tomcat-8.5.4\webapps\ROOT\distributions

3.change url like this distributionUrl=http\://localhost:8080/distributions/gradle-2.14.1-all.zip
now run as usual

0

// Do not use android 8 as it will keep downloading grade distribution use grade 7

ionic cordova platform add android@8.0.0

// This will run

ionic cordova platform add android@~7.1.1 --save

Then run below and this time it should get success( Worked for me)

ionic cordova build android

Anand_5050
  • 1,019
  • 2
  • 10
  • 23