如何重用gradle-wrapper? [英] How to reuse gradle-wrapper?

查看:136
本文介绍了如何重用gradle-wrapper?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,我从eclipse迁移到android-studio一个月。新的构建工具令人讨厌。



每一次我 git clone 一个android-sample,需要数小时才能下载它的gradle-wrapper。



我发现有很多版本的gradle-wrapper

  ninja @ ninja〜/ .gradle / wrapper / dists $ du -h --max-depth = 1 
198M ./gradle-2.2.1-all
176M ./gradle- 1.11全部
86M ./gradle-1.12-bin
85M ./gradle-2.0-bin
358M ./gradle-1.12-all
186m ./gradle-2.1-所有
1.1G。

ninja @ ninja〜/ .gradle / wrapper / dists / gradle-1.12-all $ du -h --max-depth = 1
179M ./2apkk7d25miauqf1pdjp1bm0uo
179M。 / 4ff8jj5a73a7zgj5nnzv1ubq0
358M。

有没有简单的方法从github构建项目?



以及为什么android-studio不使用我的gradle?

  ninja @ ninja 〜/ .gradle / wrapper / dists / gradle-1.11-all $ gradle -v 

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

生成时间:2014-09-08 10:40:39 UTC
版本号:无
版本:e6cf70745ac11fa943e19294d19a2c527a669a53

Groovy:2.3.6
Ant:2013年12月23日编译的Apache Ant(TM)1.9.3版本
JVM:1.7.0_67(Oracle Corporation 24.65-b04)
操作系统:Linux 3.13 .0-24-generic i386

我尝试了android-studio的设置 use local

  ninja @ ninja〜/ src / goshawk / 13_GeexFinanceSource / gradle分发,并且遇到编译错误: Geexfinance $ gradle安装调试

失败:生成失败,出现异常。

*其中:
构建文件'/home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/SlidingMenuLibrary/build.gradle'line: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秒

我需要你的帮助,有什么想法吗? .org / docs / current / userguide / gradle_wrapper.htmlrel =nofollow> 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.zip
gradle-wrapper.jar
gradle-wrapper.properties

gradlew 可执行文件在 ./ gradle中查找 gradle-wrapper.jar / wrapper /



以下是 gradle-wrapper.properties

  distributionBase = GRADLE_USER_HOME 
distributionPath =包装/ dists
zipStoreBase = GRADLE_USER_HOME
zipStorePath =包装/ dists
#将发行版手动复制到gradle / wrapper目录中进行第一次运行
#这样,发行版不需要检入版本控制
distributionUrl = gradle-2.1-bin。 zip

运行 ./ gradlew code> Project1 它会解压到〜/ .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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆