Gradle起步走: 以CLI Application為例 @ JCConf 2014
-
Upload
chen-en-lu -
Category
Technology
-
view
3.979 -
download
0
description
Transcript of Gradle起步走: 以CLI Application為例 @ JCConf 2014
![Page 2: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/2.jpg)
#JCConf�
• What is Gradle • Basic Concept • Build Simple CLI Application by Gradle
Outline
2
![Page 3: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/3.jpg)
#JCConf�
What is Gradle?
![Page 4: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/4.jpg)
#JCConf�4
鬼島?
![Page 5: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/5.jpg)
#JCConf�
Gradle is a Build Tools
5
![Page 6: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/6.jpg)
#JCConf�
source:http://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-for-2014/7/
6
![Page 7: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/7.jpg)
#JCConf�
source :http://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-for-2014/7/
7
![Page 8: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/8.jpg)
#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
![Page 9: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/9.jpg)
#JCConf�
• Features • Project Object Model • Common Build Lifecycle • Convention over Configuration • Dependency Management
• Basic Components • Project (pom.xml) • Lifecycle, Phase, Goal • Plugin
9
![Page 10: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/10.jpg)
#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
![Page 11: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/11.jpg)
#JCConf�
Gradle起步⾛走
gradle init --type=java-library
11
![Page 12: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/12.jpg)
#JCConf�
build scriptgradle wrapper
multi-project settingssource code
gradle project
12
![Page 13: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/13.jpg)
#JCConf�
build.gradle
Much Simpler Than Maven!!
13
![Page 14: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/14.jpg)
#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
![Page 15: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/15.jpg)
#JCConf�
Task Dependency (Java Plugin)
DAG (Directed Acyclic Graph)
15
![Page 16: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/16.jpg)
#JCConf�
Custom Tasks
16
![Page 17: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/17.jpg)
#JCConf�
• Simple dependency !!!
• Dynamic version !!
• Changing module !!
• Usually, we can find libraries fromhttp://mvnrepository.com/
Dependency Managementcompile '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
![Page 18: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/18.jpg)
#JCConf�
• settings.gradle !!
• Run tasks in subproject !!!!
• Dependency
Multi Projectinclude 'project1','project2'
> gradle project1:build !> cd project1 project1> gradle build
compile project(':project1')
18
![Page 19: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/19.jpg)
#JCConf�
!
Gradle IDE plugin or
IDE Gradle plugin
IDE Integration
19
![Page 20: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/20.jpg)
#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
![Page 21: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/21.jpg)
#JCConf�
• IDE Gradle plugin or native support • Gradle Daemon
IDE Integration (cont.)
Intellij Eclipse
eclipse-integration-gradleBuilt-in Gradle Plugin
21
![Page 22: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/22.jpg)
#JCConf�
Create a Simple CLI Application by Gradle (by application plugin)
https://github.com/popcornylu/jcconf2014-gradle
![Page 23: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/23.jpg)
#JCConf�23
> java -cp a.jar:b.jar:c.jar tw.jcconf.MyHello
https://github.com/popcornylu/jcconf2014-gradle
![Page 24: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/24.jpg)
#JCConf�
> java -jar myhello.jar
24
https://github.com/popcornylu/jcconf2014-gradle
![Page 25: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/25.jpg)
#JCConf�25
> myhello
https://github.com/popcornylu/jcconf2014-gradle
![Page 26: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/26.jpg)
#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
![Page 27: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/27.jpg)
#JCConf�
Demo
![Page 28: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/28.jpg)
#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
![Page 29: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/29.jpg)
#JCConf�
• Gradle User Guidehttp://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 Gradlehttp://technologyconversations.com/2014/06/18/build-tools/
Reference
29
![Page 30: Gradle起步走: 以CLI Application為例 @ JCConf 2014](https://reader034.fdocuments.net/reader034/viewer/2022042614/559445a61a28ab1a738b45b1/html5/thumbnails/30.jpg)
#JCConf�
Thanks