Gradle wrapper

The wrapper is a core feature and enables a machine to run a Gradle build script without haveing to install

the runtime.It also ensures that the build script is run with a specific version of Gradle.

 

It does so by automatically downloading the Gradle runtime from a central location,unpacking it to your local

file system,and using it for the build.

 

一、Setting up the wrapper

要给你的项目设置好wrapper,你将需要2件东西:

(1)创建一个wrapper任务

(2)执行此任务生成wrapper文件

 

为了让你的项目下载zipped Gradle runtime distribution,就要定义一个类型为Wrapper的任务,并使用

gradleVersion属性来指定版本:

 

task wrapper(type: Wrapper) {

    gradleVersion = '1.7'

}

 

任务的名字不必是wrapper,然而,这个名字在Gradle在线文档中成为了一个约定:

 

执行这个任务:

$ gradle wrapper

 



 

 

刚才的命令只需要执行一次。从那以后,你就能使用wrapper的脚本来执行你的构建。

 

二、使用wrapper

> gradlew.bat jettyRun

 

三、定制wrapper

一些企业有着非常限制性的策略,特别是如果你是为政府机构工作,访问网络外的服务器是被禁止的。

那这种情况下,如何让你的项目使用Gradle wrapper呢?那就需要修改配置:

task wrapper(type: Wrapper) {

   gradleVersion = '1.2'                              

   distributionUrl = 'http://myenterprise.com/gradle/dists'   

   distributionPath = 'gradle-dists'          

}

更多的配置请查阅Gradle wrapper DSL文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值