如何重用gradle-wrapper? [英] How to reuse gradle-wrapper?
问题描述
全部,我从 eclipse 迁移到 android-studio 一个月.新的构建工具很烦人.
每次我git clone
一个android-sample,都需要几个小时来下载它的gradle-wrapper.
我发现有很多版本的 gradle-wrapper
ninja@ninja ~/.gradle/wrapper/dists $ du -h --max-depth=1198M ./gradle-2.2.1-all176M ./gradle-1.11-all86M ./gradle-1.12-bin85M ./gradle-2.0-bin358M ./gradle-1.12-all186M ./gradle-2.1-all1.1G.ninja@ninja ~/.gradle/wrapper/dists/gradle-1.12-all $ du -h --max-depth=1179M ./2apkk7d25miauqf1pdjp1bm0uo179M ./4ff8jj5a73a7zgj5nnzv1ubq0358M.
有没有一种简单的方法可以从 github 构建项目?
为什么 android-studio 不使用我的 gradle?
ninja@ninja ~/.gradle/wrapper/dists/gradle-1.11-all $ gradle -v------------------------------------------------------------摇篮 2.1------------------------------------------------------------构建时间:2014-09-08 10:40:39 UTC版本号:无修订版:e6cf70745ac11fa943e19294d19a2c527a669a53常规:2.3.6Ant:Apache Ant(TM) version 1.9.3 2013 年 12 月 23 日编译JVM:1.7.0_67(甲骨文公司 24.65-b04)操作系统:Linux 3.13.0-24-generic i386
我尝试了android-studio的设置use local gradle distribution
,遇到编译错误:
ninja@ninja ~/src/goshawk/13_GeexFinanceSource/Geexfinance $ gradle installDebugFAILURE:构建失败,出现异常.* 在哪里:构建文件/home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/SlidingMenuLibrary/build.gradle"行:9* 什么地方出了错:评估项目:SlidingMenuLibrary"时出现问题.>未能应用插件 [id 'android-library']
<块引用>
Gradle 2.2 版是必需的.当前版本是 2.1.如果使用 gradle 包装器,请尝试将/home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/gradle/wrapper/gradle-wrapper.properties 中的 distributionUrl 编辑为 gradle-2.2-all.zip
* 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪.使用 --info 或 --debug 选项运行以获得更多日志输出.构建失败总时间:1 分 5.884 秒
我需要你的帮助,知道吗?
来自 gradle-wrapper 文档:
如果您不希望在通过 gradlew 构建项目时发生任何下载,只需将 Gradle 发行版 zip 添加到您的版本控制位置由您的包装器配置指定.支持相对 URL - 您可以指定一个相对于 gradle-wrapper.properties 位置的分发文件文件.
基本上,一旦你有了二进制文件 gradle-2.1-bin.zip
和包装器 jar gradle-wrapper.jar
,你可以简单地将它移动到任何你喜欢的地方使用正确的 gradle-wrapper.properties
和 gradlew
可执行文件.
您的项目的文件夹结构将是:
Project1 ->gradlew 或 gradlew.bat(包装器可执行文件)gradle ->包装器 ->gradle-2.1-bin.zipgradle-wrapper.jargradle-wrapper.properties
gradlew
可执行文件在 ./gradle/wrapper/
中寻找 gradle-wrapper.jar
这是一个gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME分布路径=包装器/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/dists# 首次运行时手动将发行版复制到 gradle/wrapper 目录# 这样分发就不需要被签入版本控制distributionUrl=gradle-2.1-bin.zip
当在 Project1
中运行 ./gradlew
时,它会解压到 ~/.gradle/wrapper/dists/gradle-2.1-bin/
只需将 Project1/gradle*
复制到 Project2/
即可重用包装器.
All, I migrate from eclipse to android-studio for one month. the new build tool is annoying.
Every time I git clone
a android-sample, need hours to download the its gradle-wrapper.
I found there're many version of gradle-wrapper
ninja@ninja ~/.gradle/wrapper/dists $ du -h --max-depth=1
198M ./gradle-2.2.1-all
176M ./gradle-1.11-all
86M ./gradle-1.12-bin
85M ./gradle-2.0-bin
358M ./gradle-1.12-all
186M ./gradle-2.1-all
1.1G .
ninja@ninja ~/.gradle/wrapper/dists/gradle-1.12-all $ du -h --max-depth=1
179M ./2apkk7d25miauqf1pdjp1bm0uo
179M ./4ff8jj5a73a7zgj5nnzv1ubq0
358M .
Is there a easy way to build projects from github ?
and why android-studio do not use my gradle?
ninja@ninja ~/.gradle/wrapper/dists/gradle-1.11-all $ 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(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_67 (Oracle Corporation 24.65-b04)
OS: Linux 3.13.0-24-generic i386
I tried android-studio's setting use local gradle distribution
, and meet compile errors:
ninja@ninja ~/src/goshawk/13_GeexFinanceSource/Geexfinance $ gradle installDebug
FAILURE: Build failed with an exception.
* Where:
Build file '/home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/SlidingMenuLibrary/build.gradle' line: 9
* What went wrong:
A problem occurred evaluating project ':SlidingMenuLibrary'.
> Failed to apply plugin [id 'android-library']
Gradle version 2.2 is required. Current version is 2.1. If using the gradle wrapper, try editing the distributionUrl in /home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 5.884 secs
I need your help, any idea?
From gradle-wrapper docs:
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.
Basically, once you have the binaries gradle-2.1-bin.zip
and the wrapper jar gradle-wrapper.jar
you can simply move it around where ever you please with the correct gradle-wrapper.properties
and gradlew
executable.
The folder structure of your project will be:
Project1 -> gradlew or gradlew.bat (wrapper executable)
gradle -> wrapper -> gradle-2.1-bin.zip
gradle-wrapper.jar
gradle-wrapper.properties
The gradlew
executable looks for gradle-wrapper.jar
in ./gradle/wrapper/
Here is an example of gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# copy the distribution to the gradle/wrapper directory manually for the first run
# that way the distribution doesn't need to be checked into version control
distributionUrl=gradle-2.1-bin.zip
When running ./gradlew
in Project1
it will extract to ~/.gradle/wrapper/dists/gradle-2.1-bin/
Just copy Project1/gradle*
to Project2/
to reuse the wrapper.
这篇关于如何重用gradle-wrapper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!