Gws 20141024 gradle_intro
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Gws 20141024 gradle_intro

on

  • 202 views

Gradle introduction and latest update for G*WorkshopZ 2014/10/24 (Japanese)

Gradle introduction and latest update for G*WorkshopZ 2014/10/24 (Japanese)

Statistics

Views

Total Views
202
Views on SlideShare
150
Embed Views
52

Actions

Likes
4
Downloads
5
Comments
0

3 Embeds 52

http://local.eventdots.jp 24
https://twitter.com 24
http://dev.eventdots.jp 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Gws 20141024 gradle_intro Presentation Transcript

  • 1. G*ワークショップZ Oct 2014 Gradleイントロダクション &最新動向(~2.1) 2014.10.24 須江信洋(@nobusue) http://nobusue.hatenablog.com/ https://www.facebook.com/nobuhiro.sue
  • 2. 自己紹介 } 㡲Ụ㻌ಙὒ䠄䛩䛘㻌䛾䜆䜂䜝䠅 } Twitter: @nobusue } https://www.facebook.com/nobuhiro.sue } ⣙10ᖺ䜋䛹JavaEE㛵㐃䛾௙஦䜢䛧䛶䜎䛧䛯 } 2013ᖺ10᭶䜘䜚䝣䝸䞊䝷䞁䝇(ಶே஦ᴗ୺) } ᭱㏆䛾䛚௙஦ 㻞 } IoT(Internet of Things)䛾䝃䞊䝡䝇ᇶ┙ᵓ⠏ } AWS / Cloudera Manager / CDH } Spark / Kafka / OpenTSDB / MongoDB / RStudio } Groovy / Gradle / SBT / Maven / Jenkins / Vagrant
  • 3. Gradleイントロダクション 3
  • 4. Gradleとは? } Groovy䝧䞊䝇䛾䝡䝹䝗䝒䞊䝹 } 䜽䝻䝇䝥䝷䝑䝖䝣䜷䞊䝮㻌(JavaVMୖ䛷ືస) } Groovy䝇䜽䝸䝥䝖䛷䝡䝹䝗䜢グ㏙(no more XML) } 䝡䝹䝗グ㏙䜢⡆₩䛻䛩䜛DSL䜢ᥦ౪ } つ⣙䛸ᰂ㌾ᛶ䛾㐺ษ䛺䝖䝺䞊䝗䜸䝣 } Ant:㻌ᰂ㌾䛰䛜䚸⮬⏤䛩䛞䛶㠀ຠ⋡ⓗ } Maven: つ⣙䛻䜘䜛ຠ⋡໬䚸䛧䛛䛧⼥㏻䛜ຠ䛛䛺䛔 } Gradle: つ⣙䛿䛒䜛䛜䜹䝇䝍䝬䜲䝈ྍ⬟ } ᪤Ꮡ㈨⏘䛾᭷ຠά⏝ } Ant䝍䝇䜽䜔䝡䝹䝗ᐃ⩏䜢䛭䛾䜎䜎෌฼⏝ } Maven/Ivy䝸䝫䝆䝖䝸䜢฼⏝ྍ⬟ } 䝡䝹䝗䝇䜽䝸䝥䝖ෆ䛷Java䝷䜲䝤䝷䝸䜢┤᥋฼⏝ྍ⬟ 4 http://gradle.org/
  • 5. Gradleのビルドスクリプト(例) apply plugin: 'java' repositories { jcenter() } dependencies { compile ‘org.slf4j:slf4j-api:1.7.5’ testCompile ‘junit:junit:4.11’ } 5 Java䝥䝷䜾䜲䞁䜢㐺⏝ ౫ᏑᛶゎỴ䛻 jCenter(Bintray)䜢฼⏝ 䝥䝻䝎䜽䝖䝁䞊䝗䛾౫Ꮡ䝷䜲䝤䝷䝸 䝔䝇䝖䝁䞊䝗䛾౫Ꮡ䝷䜲䝤䝷䝸
  • 6. 規約 } Java䝥䝷䜾䜲䞁䛾(䝕䝣䜷䝹䝖)䝍䝇䜽౫Ꮡ㛵ಀ 6 䛒䛟䜎䛷䝕䝣䜷䝹䝖䛷䛒䜚䚸 ⮬⏤䛻䜹䝇䝍䝬䜲䝈ྍ⬟
  • 7. Antのビルドスクリプト(例) 7 <project name="java-project" basedir="."> <property name="build.dir" value="build"/> <property name="main.src.dir" value="src/main/java"/> <property name="main.classes.dir" value="${build.dir}/classes/ main"/> <property name="test.src.dir" value="src/test/java"/> <property name="test.classes.dir" value="${build.dir}/classes/ test"/> <property name="test.results.dir" value="${build.dir}/test-results"/> <property name="reports.dir" value="${build.dir}/reports/ tests"/> <property name="jar.dir" value="${build.dir}/lib"/> <path id="junit"> <pathelement location="lib/junit-4.11.jar"/> <pathelement location="lib/hamcrest-core-1.3.jar"/> </path> <target name="clean"> <delete dir="${build.dir}"/> </target> <target name="compile"> <mkdir dir="${main.classes.dir}"/> <javac srcdir="${main.src.dir}" destdir="${main.classes.dir}" includeantruntime="false"/> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${main.classes.dir}"/> </target> <target name="testCompile"> <mkdir dir="${test.classes.dir}"/> <javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false"> <classpath> <path refid="junit"/> <path location="${jar.dir}/${ant.project.name}.jar"/> </classpath> </javac> </target> <target name="junit" depends="jar,testCompile"> <mkdir dir="${test.results.dir}"/> <junit printsummary="yes"> <classpath> <path refid="junit"/> <path location="${jar.dir}/${ant.project.name}.jar"/> <path location="${test.classes.dir}"/> </classpath> <formatter type="xml"/> <batchtest todir="${test.results.dir}"> <fileset dir="${test.classes.dir}"/> </batchtest> </junit> </target> <target name="junitreport" depends="junit"> <mkdir dir="${reports.dir}"/> <junitreport todir="${reports.dir}"> <fileset dir="${test.results.dir}" includes="TEST-*.xml"/> <report todir="${reports.dir}"/> </junitreport> </target> </project>
  • 8. Gradle DSL } Gradle䛜⊂⮬䛻ᐃ⩏䛩䜛䛂䝡䝹䝗䛃グἲ } build.gradle䛷グ㏙䛩䜛㻌apply / repositories / dependencies 䛺䛹 } Groovy䛾MOP䛺䛹䜢฼⏝䛧䛶ᐃ⩏ } DSL䛾ゎ㔘 } apply / repositories / dependencies䛾ᐇయ䛿䝯䝋䝑䝗 } ᘬᩘ䛾䜹䝑䝁䜢┬␎䛧䛶䛔䜛(Groovy䛾グἲ) } {} 䛾㒊ศ䛿Groovy䛾䜽䝻䞊䝆䝱 } 䝯䝋䝑䝗䛾䝺䝅䞊䝞䛿Gradle䛜ᥦ౪䛩䜛䝗䝯䜲䞁䜸䝤 䝆䜵䜽䝖 8
  • 9. Gradleインストール方法 } ๓ᥦ } JDK 6௨ୖ } GVM฼⏝ } curl -s get.gvmtool.net | bash } gvm install gradle } ヲ⣽䛿㻌http://gvmtool.net/ ཧ↷(Windows䛾ሙྜ䛿 Cygwin䛜ᚲせ) } ZIP䜢ᒎ㛤 } http://www.gradle.org/downloads } 㐺ᙜ䛺䝕䜱䝺䜽䝖䝸䛻ᒎ㛤㻌($GRADLE_HOME) } $GRADLE_HOME/bin㻌䛻䝟䝇䜢㏻䛧䛶䛚䛟 9
  • 10. 動作確認 } gradle -v GVM䛷䜲䞁䝇䝖䞊䝹䛧䛯ሙྜ䛿 ~/.gvm/gradle/<version>㻌௨ୗ䛻ᑟධ䛥䜜䚸 ~/.gvm/gradle/current 䛻䝅䞁䝪䝸䝑䜽䝸䞁䜽䛜సᡂ䛥䜜䜎䛩 10
  • 11. Gradle最新動向(~2.1) 11
  • 12. Gradle2.0~2.1の主要アップデート } Gradle2.0 } 䝯䝆䝱䞊䝞䞊䝆䝵䞁䜰䝑䝥䛻క䛖䜰䞊䜻䝔䜽䝏䝱䛾ᩚ⌮䛸 ྂ䛔ᶵ⬟䛾ᨵᗫ } 䝧䞊䝇䛾Groovy䛾᭱᪂໬㻌(1.8.6 䊻 2.3.2) } Java 8䝃䝫䞊䝖 } Ivy / Maven 䝸䝫䝆䝖䝸䜈䛾SFTP᥋⥆䝃䝫䞊䝖 } Gradle2.1 } 䝧䞊䝇䛾Groovy䛾᭱᪂໬㻌(2.3.2 䊻 2.3.6) } plugins 䝤䝻䝑䜽䛸䝥䝷䜾䜲䞁䝫䞊䝍䝹䛻䜘䜚䝥䝷䜾䜲䞁㐺⏝䛜ᐜ᫆䛻 } 䝥䝷䜾䜲䞁㛤Ⓨ䝥䝷䜾䜲䞁(java-gradle-plugin)䛾㏣ຍ } Java䝋䞊䝇䛾䜲䞁䜽䝸䝯䞁䝍䝹䝁䞁䝟䜲䝹ᑐᛂ } exclude ᣦᐃ䜢maven-publish䝥䝷䜾䜲䞁䛜Ⓨ⾜䛩䜛POM䛻཯ᫎ } 䝡䝹䝗䛻䜘䛳䛶⏕ᡂ䛥䜜䜛䝁䞁䝫䞊䝛䞁䝖䛾ヲ⣽᝟ሗ⾲♧䝍䝇䜽 (components)䛾㏣ຍ 12
  • 13. コミュニティプラグイン適用(~2.0) buildscript { repositories { jcenter() } dependencies { classpath "com.bmuschko:gradle-tomcat-plugin: 13 2.0" } } apply plugin: "com.bmuschko.tomcat"
  • 14. コミュニティプラグイン適用(2.1~) plugins { id "com.bmuschko.tomcat" version "2.0" } 14 䝥䝷䜾䜲䞁䝫䞊䝍䝹䛻Ⓩ㘓䛥䜜䛶䛔䜛䛣䛸䛜๓ᥦ
  • 15. Gradleプラグインポータル 15 㼔㼠㼠㼜㻦㻛㻛㼜㼘㼡㼓㼕㼚㼟㻚㼓㼞㼍㼐㼘㼑㻚㼛㼞㼓㻛
  • 16. インクリメンタルコンパイル対応 } ኚ᭦䛾䛒䛳䛯Java䝋䞊䝇䛾䜏෌䝁䞁䝟䜲䝹 } 2.0䜎䛷䛿䚸䝋䞊䝇䝉䝑䝖䛻ྵ䜎䜜䜛Java䝋䞊䝇䛾䛖䛱 ୍䛴䛷䜒ኚ᭦䛜䛒䜜䜀䚸඲య䜢෌䝁䞁䝟䜲䝹 } 2.1䛷䛿෌䝁䞁䝟䜲䝹䜢ᚲせ᭱ᑠ㝈䛻 } Ant䛾javac䝍䝇䜽䜢䜔䜑䚸Gradle⊂⮬䝁䞁䝟䜲䝷䜈 } 䝕䝣䜷䝹䝖䛷䛿↓ຠ໬䛥䜜䛶䛔䜛 } 䜲䞁䜽䝸䝯䞁䝍䝹䝁䞁䝟䜲䝹䛾ຠᯝ } 䝡䝹䝗᫬㛫▷⦰ } 䝞䜲䝖䝁䞊䝗ฎ⌮䜔ືⓗ䜽䝷䝇䝸䝻䞊䝗䜢⾜䛖ሙྜ 䛾ᙳ㡪⠊ᅖ䛾᭱ᑠ໬ 16
  • 17. インクリメンタルコンパイル有効化 } 䝡䝹䝗䝇䜽䝸䝥䝖㻌or ึᮇ໬䝇䜽䝸䝥䝖䛻㏣グ } ึᅇ䝡䝹䝗᫬䛻䜽䝷䝇ゎᯒ䝕䞊䝍䜢グ㘓䛧䚸௨㝆䛿ᕪ ศ䜢䝏䜵䝑䜽䛩䜛 17 allprojects { tasks.withType(JavaCompile) { options.incremental = true } }
  • 18. 18 参考情報
  • 19. Gradle関連情報 } Gradle䝗䜻䝳䝯䞁䝖 } http://www.gradle.org/documentation } Gradle䝗䜻䝳䝯䞁䝖(᪥ᮏㄒ⩻ヂ∧) } http://gradle.monochromeroad.com/docs/index.html 䋻බᘧ䝗䜻䝳䝯䞁䝖䛻⛣⾜ணᐃ䛷䛩 } 䝃䞁䝥䝹䝁䞊䝗 } gradle-x.x-all.zip䛾”samples/”௨ୗ } 䝋䞊䝇䝁䞊䝗 } https://github.com/gradle/gradle 19
  • 20. 20 㼔㼠㼠㼜㻦㻛㻛㼣㼣㼣㻚㼜㼕㼤㼕㼢㻚㼚㼑㼠㻛㼙㼑㼙㼎㼑㼞㼋㼕㼘㼘㼡㼟㼠㻚㼜㼔㼜㻫㼙㼛㼐㼑㻩㼙㼑㼐㼕㼡㼙㻒㼕㼘㼘㼡㼟㼠㼋㼕㼐㻩㻠㻝㻢㻣㻠㻠㻡
  • 21. 21 次は 「Gradleハンズオン基礎編」 です