我是靠谱客的博主 疯狂小蝴蝶,最近开发中收集的这篇文章主要介绍gradle使用,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

官方指导手册:http://www.gradle.org/docs/2.0/userguide/userguide.html

1、gradle 常用命令:
gradle build
gradle test
gradle compilejava
gradle jar
gradle clean
gradle jar
gradle init
//生成wrapper包
gradle wrapper
gradle compilejava
gradle javadoc
gradle dependencies
gradle help
gradle check
gradle test
gradle -v
gradle --info
gradle --debug
gradle --help
列出可执行的所有任务(即查看可以执行的命令)
gradle tasks
gradle -q tasks
依赖:
compile
The dependencies required to compile the production source of the project.


runtime
The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies.


testCompile
The dependencies required to compile the test source of the project. By default, also includes the compiled production classes and the compile time dependencies.


testRuntime
The dependencies required to run the tests. By default, also includes the compile, runtime and test compile dependencies.


gradle -m clean compileJava
进入GUI界面
gradle --gui
gradle IDE
E.1. IntelliJ
E.2. Eclipse

2、gradle实例:

apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
//可以自定义中央仓库
maven {
url "http://repo.mycompany.com/maven2"
}
}
def dest = "dest"
task copy(type: Copy) {
description='复制脚本'
from "source"
into dest
}
task getinfo<<{
description='获取gradle工程基本信息'
println project.name;
println project.description;
println project.buildDir.canonicalPath;
println project.defaultTasks.toListString;
println project.gradle.gradleHomeDir.absolutePath;
println project.gradle.gradleUserHomeDir.absolutePath;
println project.gradle.gradleVersion;
println project.properties.toMapString;
println project.getDefaultTasks().toListString;
}
task wrapper(type: Wrapper) {
description='任务描述,各种说明'
gradleVersion = '2.0'
}
task fileinfo << {
println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
}
//
task hello << {
println 'Hello Earth'
}
hello.doFirst {
println 'Hello Venus'
}
hello.doLast {
println 'Hello Mars'
}
hello << {
println 'Hello Jupiter'
}
//动态依赖 执行命令: gradle -q task1 、 gradle -q task3
4.times { counter ->
task "task$counter" << {
println "I'm task number $counter"
}
}
task taskX(dependsOn: 'hello_intro') << {
println 'taskX'
}
//任务依赖
task hello_intro << {
println 'Hello world!'
}
task intro(dependsOn: hello_intro) << {
println "I'm Gradle"
}
//我是注释,数字遍历
task count << {
40.times { print "$it " }
}
/**
* 大小写转换
*/
task upper << {
description='大小写转换'
String someString = 'uper DEMO mY_nAmE'
println "Original: " + someString
println "Upper case: " + someString.toUpperCase()
println "lower case: " + someString.toLowerCase()
}
task hello2<<{
println("hello2")
}
task hello3{
//doLast是方法
doLast{
println("Hello world! Love you,gradle")
}
}
task fuck<<{
println 'fuck'
}
task mytask<<{
if(System.properties['path'])
{
println("i love java and gradle")
}else{
println("fuck");
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.springframework:spring-context:3.0.4.RELEASE'
compile group:'commons-collections',name:'commons-collections',version:'3.2'
compile('com.alibaba:fastjson:1.2.0')
}



最后

以上就是疯狂小蝴蝶为你收集整理的gradle使用的全部内容,希望文章能够帮你解决gradle使用所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(27)

评论列表共有 0 条评论

立即
投稿
返回
顶部