Gradle简单使用

  1. Gradle基本简介
    Gradle构建脚本的书写没有基于传统的XML文件,而是基于Groovy的领域专用语言,Gradle有约定优于配置的原则,相比Maven更容易上手。
  2. Groovy基本语法
    Groovy是一种基于java虚拟机的动态语言
#定义变量
def a = '123'
#定义集合
def testList = ['123','456']
def testMap = ['key1':'123', 'key2':'456']
#集合添加元素
testList << '789'
testMap.key3 = '789'
#集合遍历(it是个关键字代表每个元素)
testList.each{ println("${it}") }
testMap.each{ println it.getValue() }
#闭包方法的两种写法
def method1 = {
    closure ->
    closure()
}
def method4(Closure closure){
    closure("测试")
}
def method2 = {
    println('aaaaaaa')
}
def method3 = {
    value ->
        println("${value}")
}
method1 (method2)
method4 (method3)
  1. gradle基本使用
    Gradle每次构建都包括至少一个项目,每个项目又包括一个或多个任务,每个build.gradle文件都代表一个项目任务定义在该文件的构建脚本里
#声明插件,一版插件中会带来很多已经写好的任务  
apply plugin: 'java'
#定义仓库
repositories {
    mavenCentral()
    mavenLocal()
    ivy {
            credentials {
                username "username"
                password "pw"
            }
            url "http://repo.mycompany.com"
        }
}
#定义依赖
dependencies {
    #添加文件依赖
    compile fileTree(dir: "libs", include: ["*.jar"])
    #编译阶段
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
    #测试阶段
    testCompile group: 'junit', name: 'junit', version: '4.+'
    #测试和运行
    runtime group: 'commons-codec', name: 'commons-codec', version: '1.+'
    #测试运行时
    testRuntime 'org.jmock:jmock-legacy:2.11.0'
    #添加项目模块作为依赖
    compile project(':library')
}
#定义project带不进来的额外属性
ext {
    springVersion = "3.1.0.RELEASE"
    emailNotification = "build@master.org"
}
#定义任务
task('hello') <<
{
    println "hello"
}
#访问任务
task hello
#重写任务
task hello(overwrite: true) << {
    println('I am the new one.')
}  
#定义一个拷贝任务
task copyTask(type: Copy) {
    from 'src/main/webapp'
    into 'build/explodedWar'
}  
  1. gradle基本命令行调用语法
gradle tasks //查看所有任务 
gradle hello //调用hello任务

gradle在安卓中的使用,快速楼梯点我

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值