参考:
How to use gradle zip in local system without downloading when using gradle-wrapper
下面是原贴内容:
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.
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 viagradlew, 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.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.
---------------------------------------------------------------------下面是个人总结---------------------------------------------------------------
如果不更改项目里gradle/wrapper/gradle-wrapper.propertis文件,执行./gradlew 命令后发现显示:
Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip
说明就开始联网开始下载gradle了,但是无网络的情况下或者在内网情况下根本无法下载,这个时候怎么办?
接下来就是解决这个问题:
如果之前下载过gradle,那么,
对于linux,会在:/home/root/.gradle/wrapper/dists/gradle-2.14.1-all目录下看到很多杂乱的字符串命名的文件夹,打开文件夹就可以找到gradle-2.14.1-all.zip压缩包。
对于windows,会在:C:\Users\Adminstrator\.gradle\wrapper\dists\gradle-2.14.1-all目录下看到很多杂乱的字符串命名的文件夹,打开文件夹就可以找到gradle-2.14.1-all.zip压缩包。
也可以在android-studio文件夹下找到gradle文件夹里面的gradle-2.14.1这个文件夹,压缩后也可以使用。
当然也可以外网下下载好gradle-2.14.1-all.zip后放入内网电脑。
不管用上面哪一种方法,把上面得到的gradle-2.14.1.zip压缩包拷贝到项目的gradle/wrapper目录下,然后把项目里gradle/wrapper/gradle-wrapper.propertis文件的distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip改为distributionUrl=gradle-2.14.1-all.zip
做完上面的步骤,然后在项目目录下执行./gradlew等一系列命令就不会去联网下载gradle了