官方指導手冊: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')
- }