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實例:

[java] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. apply plugin: 'java'  
  2.   
  3. sourceCompatibility = 1.5  
  4. version = '1.0'  
  5.   
  6. repositories {  
  7.     mavenCentral()  
  8.     //可以自定義中央倉庫  
  9.     maven {  
  10.         url "http://repo.mycompany.com/maven2"  
  11.     }  
  12. }  
  13.   
  14.   
  15. def dest = "dest"  
  16. task copy(type: Copy) {  
  17.     description='複製腳本'  
  18.     from "source"  
  19.     into dest  
  20. }  
  21.   
  22.   
  23. task getinfo<<{  
  24.     description='獲取gradle工程基本信息'  
  25.     println project.name;  
  26.     println project.description;  
  27.     println project.buildDir.canonicalPath;  
  28.     println project.defaultTasks.toListString;  
  29.     println project.gradle.gradleHomeDir.absolutePath;  
  30.     println project.gradle.gradleUserHomeDir.absolutePath;  
  31.     println project.gradle.gradleVersion;  
  32.     println project.properties.toMapString;  
  33.     println project.getDefaultTasks().toListString;  
  34.   
  35. }  
  36.   
  37.   
  38.   
  39. task wrapper(type: Wrapper) {  
  40.     description='任務描述,各種說明'  
  41.     gradleVersion = '2.0'  
  42. }  
  43.   
  44. task fileinfo << {  
  45.     println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."  
  46. }  
  47.   
  48. //  
  49. task hello << {  
  50.     println 'Hello Earth'  
  51. }  
  52. hello.doFirst {  
  53.     println 'Hello Venus'  
  54. }  
  55. hello.doLast {  
  56.     println 'Hello Mars'  
  57. }  
  58. hello << {  
  59.     println 'Hello Jupiter'  
  60. }  
  61.   
  62.   
  63. //動態依賴 執行命令: gradle -q task1 、 gradle -q task3  
  64. 4.times { counter ->  
  65.     task "task$counter" << {  
  66.         println "I'm task number $counter"  
  67.     }  
  68. }  
  69.   
  70. task taskX(dependsOn: 'hello_intro') << {  
  71.     println 'taskX'  
  72. }  
  73.   
  74. //任務依賴  
  75. task hello_intro << {  
  76.     println 'Hello world!'  
  77. }  
  78. task intro(dependsOn: hello_intro) << {  
  79.     println "I'm Gradle"  
  80. }  
  81.   
  82. //我是註釋,數字遍歷  
  83. task count << {  
  84.     40.times { print "$it " }  
  85. }  
  86. /** 
  87.  * 大小寫轉換 
  88.  */  
  89. task upper << {  
  90.     description='大小寫轉換'  
  91.     String someString = 'uper DEMO mY_nAmE'  
  92.     println "Original: " + someString  
  93.     println "Upper case: " + someString.toUpperCase()  
  94.     println "lower case: " + someString.toLowerCase()  
  95. }  
  96. task hello2<<{  
  97.     println("hello2")  
  98. }  
  99. task hello3{  
  100.     //doLast是方法  
  101.     doLast{  
  102.         println("Hello world! Love you,gradle")  
  103.     }  
  104. }  
  105.   
  106. task fuck<<{  
  107.     println 'fuck'  
  108. }  
  109. task mytask<<{  
  110.     if(System.properties['path'])  
  111.     {  
  112.         println("i love java and gradle")  
  113.   
  114.     }else{  
  115.         println("fuck");  
  116.     }  
  117. }  
  118. dependencies {  
  119.     testCompile group: 'junit', name: 'junit', version: '4.11'  
  120.     compile 'org.springframework:spring-context:3.0.4.RELEASE'  
  121.     compile group:'commons-collections',name:'commons-collections',version:'3.2'  
  122.     compile('com.alibaba:fastjson:1.2.0')  
  123.   
  124. }  

發佈了39 篇原創文章 · 獲贊 5 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章