O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Gradle起步走: 以CLI Application為例 @ JCConf 2014

在 Java 的 Build System 當中,早期是 Ant 的天下,接下來漸漸被 Maven 取代,再到最近越來越多的人選擇使用 Gradle。由於 Gradle 的簡單強大,而且沿用了 Maven Central Repository,讓我們的專案可以更輕鬆的管理。此次分享以 CLI(Command Line Interface) 應用程式為例,從產生一個Gradle專案,整合 third party library,整合主流的 IDE,最後產生一個方便執行的 shell script,全部搞定。在短短的15分鐘,希望給還沒用過 Gradle 的朋友感受 Gradle 的魅力。

  • Entre para ver os comentários

Gradle起步走: 以CLI Application為例 @ JCConf 2014

  1. 1. #JCConf Gradle 起步⾛走: 以 CLI Application 為例 陸振恩 (popcorny)
 popcorny@cacafly.com
  2. 2. #JCConf • What is Gradle • Basic Concept • Build Simple CLI Application by Gradle Outline 2
  3. 3. #JCConf What is Gradle?
  4. 4. #JCConf4 鬼島?
  5. 5. #JCConf Gradle is a Build Tools 5
  6. 6. #JCConf source:
 http://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-for-2014/7/ 6
  7. 7. #JCConf source :
 http://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-for-2014/7/ 7
  8. 8. #JCConf • Features • ‘make’ in the java ecosystem • Pure java • Target dependency • Basic Components • Project (build.xml) • Target (eg. build, clean, deploy, …) • Task (javac, jar, copy, …) 8
  9. 9. #JCConf • Features • Project Object Model • Common Build Lifecycle • Convention over Configuration • Dependency Management • Basic Components • Project (pom.xml) • Lifecycle, Phase, Goal • Plugin 9
  10. 10. #JCConf • Features • Groovy-based DSL (Domain Specific Language)
 - Not XML configuration any more • Dependency Management 
 - Integrate Maven repository • Task Dependency
 - Like target dependency in ant • Plugins provide the out-of-the-box tasks
 - Like lifecycle in maven • Basic Components • Project (build.gradle) • Task • Plugin 10
  11. 11. #JCConf Gradle起步⾛走 gradle init --type=java-library 11
  12. 12. #JCConf build script gradle wrapper multi-project settings source code gradle project 12
  13. 13. #JCConf build.gradle Much Simpler Than Maven!! 13
  14. 14. #JCConf [Default] • gradle tasks 
 - List the tasks • gradle dependencies 
 - Display the library dependencies.
 [Java Plugin] • gradle build 
 - Build the project • gradle test
 - Test the project • gradle jar
 - Generate the jar file • gradle clean 
 - Clean the project. Useful Tasks 14
  15. 15. #JCConf Task Dependency
 (Java Plugin) DAG (Directed Acyclic Graph) 15
  16. 16. #JCConf Custom Tasks 16
  17. 17. #JCConf • Simple dependency ! ! ! • Dynamic version ! ! • Changing module ! ! • Usually, we can find libraries from
 http://mvnrepository.com/ Dependency Management compile 'org.slf4j:slf4j-api:1.7.5' testCompile 'junit:junit:4.11' compile 'org.slf4j:slf4j-api:1.7.+' compile 'tw.jcconf:myapp:1.0-SNAPSHOT' 17
  18. 18. #JCConf • settings.gradle ! ! • Run tasks in subproject ! ! ! ! • Dependency Multi Project include 'project1','project2' > gradle project1:build ! > cd project1 project1> gradle build compile project(':project1') 18
  19. 19. #JCConf ! Gradle IDE plugin or IDE Gradle plugin IDE Integration 19
  20. 20. #JCConf • Gradle IDE plugin ! ! ! • Tasks • gradle eclipse • gradle idea • Create the project file and put the jars in the IDE classpath. IDE Integration (cont.) apply plugin:’eclipse’ apply plugin:’idea’ 20
  21. 21. #JCConf • IDE Gradle plugin or native support • Gradle Daemon IDE Integration (cont.) Intellij Eclipse eclipse-integration-gradleBuilt-in Gradle Plugin 21
  22. 22. #JCConf Create a Simple CLI Application by Gradle (by application plugin) https://github.com/popcornylu/jcconf2014-gradle
  23. 23. #JCConf23 > java -cp a.jar:b.jar:c.jar tw.jcconf.MyHello https://github.com/popcornylu/jcconf2014-gradle
  24. 24. #JCConf > java -jar myhello.jar 24 https://github.com/popcornylu/jcconf2014-gradle
  25. 25. #JCConf25 > myhello https://github.com/popcornylu/jcconf2014-gradle
  26. 26. #JCConf • Tasks • gradle run • gradle installApp • gradle distZip • gradle distTar Application Plugin 26 > tree build/install/myhello/ build/install/myhello/ ├── bin │   ├── myhello │   └── myhello.bat └── lib ├── commons-cli-1.2.jar ├── myhello.jar └── slf4j-api-1.7.5.jar https://github.com/popcornylu/jcconf2014-gradle
  27. 27. #JCConf Demo
  28. 28. #JCConf • Gradle exploit advantages from ant and maven • Flexible like Ant • Convention over configuration • Dependency management • Out-of-the-box tasks ! • Use DSL instead of XML • Good IDE integration Recap 28
  29. 29. #JCConf • Gradle User Guide
 http://www.gradle.org/docs/current/userguide/ userguide_single.html
 • Gradle Tutorial in CodeData (by qrtt1)
 http://www.codedata.com.tw/java/understanding-gradle-1- ant/
 • Hibernate. Why Gradle?
 https://developer.jboss.org/wiki/GradleWhy
 • Java Build Tools: Ant vs Maven vs Gradle
 http://technologyconversations.com/2014/06/18/build-tools/ Reference 29
  30. 30. #JCConf Thanks

×