http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.Copy.html
http://www.cnblogs.com/CloudTeng/p/3417762.html
http://www.blogjava.net/wldandan/archive/2012/06/27/381605.html
学习记录:
/**gradle include two parts [part1:project, part2:task] */ /*****************调用Project的task()方法创建Task start*************/ task hello << { println "the current task name is $name" println "hello world" } /*****************调用Project的task()方法创建Task end*************/ /*****************通过TaskContainer的create()方法创建Task start*****************/ tasks.create(name: 'hello4') << { println 'hello4' } /*****************通过TaskContainer的create()方法创建Task end*****************/ /*****************声明Task之间的依赖关系 start*********************/ task hello5(dependsOn:hello4) << { println 'hello5' } task hello6 << { println 'hello6' } hello6.dependsOn hello5 /*****************声明Task之间的依赖关系 end*********************/ /*****************配置Task属性start ******************/ //定义Task的时候对Property进行配置 task hello7 << { description = "this is hello7" println description } //调用Task的configure()方法完成Property的设置 task hello9 << { println description } hello9.configure { description = "this is hello9" } /*****************配置Task属性end*****************/ /***************通过定义输入输出实现增量构建 start*******************/ task combineFileContentIncremental { def sources = fileTree('sourceDir') def destination = file('destination.txt') inputs.dir sources outputs.file destination doLast { destination.withPrintWriter { writer -> sources.each {source -> writer.println source.text } } } } /***************通过定义输入输出实现增量构建 end*******************/ /*****************自定义Property start*********************/ //在build.gradle文件中向Project添加额外的Property时,我们并不能直接定义,而是应该通过ext来定义 ext { property2 = "this is property2" } /*****************自定义Property end*********************/ /*****************重新设置main的目录结构start***************/ sourceSets { main { java { srcDir 'java-sources' } resources { srcDir 'resources' } } } /*****************重新设置main的目录结构end***************/ /****************创建新的source set start****************/ sourceSets { api } /****************创建新的source set end****************/ /******************一部分项目配置start******************/ configure(allprojects.findAll { it.name.startsWith('sub') }) { subTask << { println 'this is a sub project' } } /******************一部分项目配置end******************/ /******************单个配置start******************/ project(':sub-project1') { task forProject1 << { println 'for project 1' } } /******************单个配置end******************/ subprojects { apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'war' repositories { mavenCentral() } dependencies { /****************直接依赖本地jar包start********************/ //单文件依赖 //compile files('libs/ojdbc14-10.2.0.1.0.jar') //某个文件夹下面全部依赖 compile fileTree(dir: 'libs', includes: ['*.jar']) runtime fileTree(dir: 'libs', includes: ['*.jar']) /****************直接依赖本地jar包end********************/ /****************依赖于Project start*******************/ dependencies { compile project(':ProjectB') } /****************依赖于Project end**********************/ testCompile 'junit:junit:4.8.2' } version = '1.0' jar { manifest.attributes provider: 'my cool company' } }