SlideShare a Scribd company logo
1 of 66
Download to read offline
G*ワークショップZ
Gradleハンズオン

       2013.03.15(3.18更新)
        須江信洋(@nobusue)
                 http://d.hatena.ne.jp/nobusue
        https://www.facebook.com/nobuhiro.sue
自己紹介
       須江 信洋(すえ のぶひろ)
           Twitter: @nobusue
           https://www.facebook.com/nobuhiro.sue
       約10年ほどJavaEE関連の仕事をしてます
       最近はPhoneGap(Cordova)とかがメイン
       G*(Groovy関連技術)との関わり
           JGGUGサポートスタッフ
           「プログラミングGROOVY」執筆チーム
           「Groovy イン・アクション」翻訳チーム
           Groovyで作ったBot飼ってます(@hatena_groovy)

    2
agenda
       Gradle概要 (thanks to 林さん)
       Gradleインストール
       Hello Gradle
       Gradle Tools
       Gradle Quickstart
       Gradle Build Language概要
       Ant integration
       IDE integration
       Jenkins integration
       便利なGradleプラグイン紹介
       参考情報
    3
本日のサンプルコード
   GitHubから入手してください
       https://github.com/nobusue/GradleHandson
       git clone
        https://github.com/nobusue/GradleHandson


   より詳しい例はGradle公式サンプルを参照
       http://www.gradle.org/downloads
       gradle-1.4-all.zipの”samples”ディレクトリ



4
Gradleインストール
       前提
           JDK1.5以上 (“java –version”で確認)
       GVM利用
           curl -s get.gvmtool.net | bash
           gvm install gradle
           詳細は http://gvmtool.net/ 参照
           Windowsの場合はcygwinが必要
       ZIPを展開
           http://www.gradle.org/downloads
           gradle-1.4-all.zipかgradle-1.4-bin.zip
           適当なディレクトリに展開 ($GRADLE_HOME)
           $GRADLE_HOME/bin にパスを通しておく

    5
動作確認
   gradle -v




    GVMでインストールした場合は ~/.gvm/gradle/1.4 以下に導入され、
    ~/.gvm/gradle/current にシンボリックリンクが作成されます
6
Hello Gradle
 適当な作業ディレクトリを作成し、カレントディ
  レクトリを移動します
 以下の内容で”build.gradle”を作成します
    task helloWorld << {
      println 'Hello world.'
    }

   “gradle helloWorld” を実行します



7
Hello Gradle解説
                        タスクにクロージャを追加
     タスクの定義             ※ leftShift()の省略記法



    task helloWorld << {
      println 'Hello world.'
    }

      Groovyのprintln文




8
デフォルトGradleタスク
   gradle tasks




9
Gradle Tools
 gradle command
 gradle daemon
 gradle-gui




10
gradle command
   gradle --help




11
gradle commandの重要オプション
   ログ関連
       --quiet(-q) ログ出力を抑制
       --info(-i) / --debug(-d)
       --stacktrace(-s) / --full-stacktrace(-S)
   ファイル/ディレクトリ指定
       --build-file(-b) build.gradle以外
       --project-dir(-p) カレントディレクトリ以外
   テスト
       --dry-run(-m) タスクの実行順序のみ確認

12
環境まわりのまとめ
   環境変数
       JAVA_OPTS ⇒JVM全体に影響
       GRADLE_OPTS ⇒gradleのみ影響
   初期化スクリプト(init scripts)
       ビルドの開始前に実行される
       ~/.gradle/init.gradle
       ~/.gradle/init.d/*.gradle
       $GRADLE_HOME/init.d/*.gradle
       --init-script(-I)で指定することも可能

13
gradle daemon
    gradleのプロセスを常駐して起動を高速化
    起動
        gradle --daemon helloWorld
    停止
        gradle --stop
    起動済みのプロセスを使わない
        gradle –no-daemon helloWorld
    常にdaemonを使う場合は以下いずれか
        alias gradled=‘gradle --daemon’
        export GRADLE_OPTS=
         “-Dorg.gradle.daemon=true”
    14
gradle-gui
   gradle --gui




15
Gradle Quickstart
 Java project
 Groovy project
 Web project




16
Javaプロジェクトのレイアウト
.

                           Mavenと同様の規約に従って
├── build.gradle
└── src
    ├── main
    │   ├── java
                           プロダクトコードとテストコードを
    │
    │
        │
        │
            └── org
                └── gradle
                                  配置
    │   │           └── Person.java
    │   └── resources
    │       └── org
    │           └── gradle
    │               └── resource.xml
    └── test
        ├── java
        │   └── org
        │       └── gradle
        │           └── PersonTest.java
        └── resources
            └── org
                └── gradle
                    └── test-resource.xml
17
Javaプロジェクトのビルドスクリプト(抜粋)
apply plugin: 'java'     Javaプラグインを適用

repositories {
  mavenCentral()       依存性解決にMavenリポジトリを利用
}
                          プロダクトコードのコンパイル時の依存先
dependencies {
  compile(
      group: 'commons-collections',
      name: 'commons-collections',
      version: '3.2')
  testCompile(                テストコードのコンパイル時の依存先
      group: 'junit',
      name: 'junit',
      version: '4.+')
}
18
Javaプラグインが追加するタスク
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that
depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles the main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles the test classes.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

    19
Javaプラグインが追加するタスク
Upload tasks
------------
uploadArchives - Uploads all artifacts belonging to configuration ':archives'

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

Rules
-----
Pattern: build<ConfigurationName>: Assembles the artifacts of a
configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts
belonging to a configuration.
Pattern: clean<TaskName>: Cleans the output files of a task.
   20
Groovyプロジェクトのレイアウト
     .
     ├── build.gradle
     └── src
         ├── main
         │   ├── groovy
         │   │   └── org
         │   │       └── gradle
         │   │           └── Person.groovy
         │   └── resources
         │       ├── resource.txt
         │       └── script.groovy
         └── test
             ├── groovy
             │   └── org
             │       └── gradle
             │           └── PersonSpec.groovy
             └── resources
                 ├── testResource.txt
                 └── testScript.groovy


21
Groovyプロジェクトのビルドスクリプト


                             Groovyプラグインを適用
apply plugin: 'groovy'

repositories {             依存性解決にMavenリポジトリを利用
  mavenCentral()
}                           プロダクトコードのコンパイル時の依存先

dependencies {
  compile 'org.codehaus.groovy:groovy-all:2.0.5'
  testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
                              テストコードのコンパイル時の依存先


  22
Groovyプラグインが追加するタスク
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Documentation tasks
groovydoc - Generates Groovydoc API documentation for the main
source code.



GroovyプラグインはJavaプラグインを拡張して作られているため、
Javaプラグインが提供するタスクはそのまま利用可能
(ただし、一部のタスクはGroovy用に機能拡張されている)



   23
Webappプロジェクトのレイアウト
     .
     ├── build.gradle
     └── src
         └── main
             ├── java
             │   └── org
             │       └── gradle
             │           └── sample
             │               └── Greeter.java
             ├── resources
             │   └── greeting.txt
             └── webapp
                 └── index.jsp




24
Webappプロジェクトのビルドスクリプト
                                Warプラグインを適用
apply plugin: 'war'
apply plugin: 'jetty'
                                Jettyプラグインを利用して
                              ビルドスクリプト上でwarを実行可能
repositories {
  mavenCentral()
}                             依存性解決にMavenリポジトリを利用

dependencies {
  compile group: 'commons-io', name: 'commons-io', version: '1.4'
  compile group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}
                                       プロダクトコードのコンパイル時の依存先

httpPort = 8080
stopPort = 9451
stopKey = 'foo'                         Jettyプラグインのパラメータ


   25
Webappプラグインが追加するタスク
Build tasks
-----------
war - Generates a war archive with all the compiled classes, the web-app
content and the libraries.

Web application tasks
---------------------
jettyRun - Uses your files as and where they are and deploys them to Jetty.
jettyRunWar - Assembles the webapp into a war and deploys it to Jetty.
jettyStop - Stops Jetty.


WebappプラグインはJavaプラグインを拡張して作られているため、
Javaプラグインが提供するタスクはそのまま利用可能
(ただし、一部のタスクはWebapp用に機能拡張されている)
    26
Gradle Build Language概要
 Gradle DSL
 Gradle Domain Objects




27
Gradle DSLのエントリーポイント
   Gradleビルド言語リファレンス
       http://gradle.monochromeroad.com/docs/
        dsl/index.html




28
タスク定義
    task('hello') << {               task(hello) << {
       println "hello"                  println "hello"
    }                                }

    task('copy', type: Copy) {       task(copy, type: Copy) {
       from(file('srcDir'))             from(file('srcDir'))
       into(buildDir)                   into(buildDir)
    }                                }


task copy(type: Copy) {
  description = 'Copies the resource directory to the target directory.'
  from 'resources'
  into 'target'
  include('**/*.txt', '**/*.xml', '**/*.properties')
}
   29
デフォルトタスク
     defaultTasks 'clean', 'run'

     task clean << {
        println 'Default Cleaning!'
     }

     task run << {
        println 'Default Running!'
     }

     task other << {
        println "I'm not a default task!"
     }


30
タスク依存関係(task利用)
task taskX << {
   println 'taskX'
}

task taskY << {
   println 'taskY'
}

taskX.dependsOn taskY


            タスク名でtaskオブジェクトを参照




31
タスク依存関係(クロージャ利用)
     task taskX << {
        println 'taskX'
     }
     taskX.dependsOn {
        tasks.findAll { task -> task.name.startsWith('lib') }
     }

     task lib1 << {
        println 'lib1'        taskのコレクションを返すクロージャ
     }
     task lib2 << {
        println 'lib2'
     }
     task notALib << {
        println 'notALib'
     }

32
description/グループ化
def taskGroup = 'base‘
task first(description: 'Base task', group: taskGroup) << {
  println "I am first task"
}                                             groupを指定

task second(dependsOn: first, description: 'Secondary task',
group: taskGroup) << {
  println "I am second task"
}




33
動的タスク定義
4.times { counter ->
  task "task${counter}" << {
    println "${counter+1}番目の動的タスクです"
  }
}




34
条件分岐
task "OsDependTask" << {
  def os = System.getProperty("os.name")
  if(os.contains("Windows")) {
    println "Windows用の処理" }
  else if(os.contains("Mac OS")) {
    println "Mac OS用の処理" }
  else { println "Linux/Unix用の処理" }
}




35
Gradleの代表オブジェクト
   org.gradle.api.Project
       ビルドスクリプト(build.gradle)に対応
       中核となるオブジェクト
       ビルドスクリプト内では暗黙的に、もしくはproject
        プロパティで参照




36
Gradleの代表オブジェクト
   org.gradle.api.invocation.Gradle
       実行中のビルドエンジンに対応
       初期化時の情報や、環境情報を保持
       Project.getGradle() で取得可能




37
Gradleの代表オブジェクト
   org.gradle.api.initialization.Settings
       settings.gradleに対応
       マルチプロジェクト構成時にプロジェクト階層の情
        報を保持




38
便利メソッド/プロパティ
    file()
        相対/絶対パス、Fileオブジェクト、URLなど
        PathValidationでいろいろ判定可能
    files()
        ファイルのコレクション(filter可能)
        引数としてファイルを返すtaskを渡せる
    fileTree()
        ファイルのツリー階層をトラバース(visit)可能
        Antのpathelement式でinclude/exclude可能
    logger
        SLF4J Loggerのインスタンス
        標準出力への出力はQUIETレベルにリダイレクト
    39
拡張プロパティ
    Gradleのドメインモデルにプロパティを追加する
     際には、extプロパティ(extブロック)を使うこと
        Gradle-1.0M9からこちらが強く推奨されています
        現在は互換性のため未定義のプロパティがあってもエ
         ラーにならないが、警告が出ます
    ローカル変数(def)と異なり、ドメインモデルのラ
     イフサイクル全体で利用できます
    詳細はこちらの「13.4.2. 拡張プロパティ」を参照
        http://gradle.monochromeroad.com/docs/use
         rguide/writing_build_scripts.html

    40
Ant integration
 Antタスクの利用
 Antビルド定義の利用




41
AntからGradleへ
    Gradleは既存のAnt資産を活用できる
        Antのbuild.xmlをそのまま読み込んで実行可能
          Antターゲット=Gradleタスク
        AntタスクをGradleから直接利用可能
            GroovyのAntBuilderが組み込まれている
        AntタスクとGradleタスクを共存することも可能
          相互に依存するタスクも定義できる
          AntタスクをGradleから拡張することもできる


    Gradleは「Better Ant」としても使える
        Mavenとの大きな違い
        Antから段階的にGradleへ移行できる

    42
GradleでAntタスクを利用

task hello << {
      ant.echo('Antタスクの実行')
}




43
GradleでAntのビルド定義を利用
[build.gradle]
ant.importBuild 'build.xml'
[build.xml]
 <project>
  <target name="hello">
    <echo>Antターゲットの実行</echo>
  </target>
 </project>




 44
IDE integration
 IntelliJ IDEA
 Eclipse




45
IntelliJ IDEA
   Gradle -> IntelliJ
       gradle IntelliJ pluginを利用
         apply plugin: 'idea'
       IDEA固有リソースを生成


   IntellJ Gradle plugin(JetGradle)
       Preferences -> Plugins -> Gralde
       ウィンドウ右端の「JetGradle」を開いてみよう!


46
IntelliJ IDEA: Gradle build confing




47
IntelliJ IDEA: JetGradle




48
Eclipse
   Gradle -> Eclipse
       gradle Eclipse pluginを利用
         apply plugin: ‘eclipse'
       Eclipse固有リソースを生成
         ただし、使いこなすにはいろいろ癖が・・・


   Eclipse Gradle plugin
       STSの一部として提供
         http://dist.springsource.com/release/TO
          OLS/gradle

49
Eclipse: installing Gradle plugin




50
Eclipse: Gradle Tasks view




51
Jenkins integration
 Gradle wrapper
 Jenkis Gradle plugin




52
Jenkinsとの統合 - Gradle
   Gradle wrapperを利用
       JDKさえ導入されていれば、Gradleを自動でイン
        ストールして実行してくれる
       Jenkins上では汎用コマンドとして実行すればよい


   Gradle wrapperは、CI用途に限らず、
    開発者の環境構築負荷軽減にも有用



53
Gradle wrapper
 [build.gradle]
 task wrapper(type: Wrapper) {
    gradleVersion = '1.4'
 }

  Gradle導入済の環境で"gradle wrapper"を実行
すると、Gradleのブートストラップ(gradlew)が生成される



                                 バージョン管理
                                  システム



  54
Jenkinsのビルド設定




55
Jenkinsのテストレポート設定
   JUnitと同様




56
Jenkins Gradle plugin
   Jenkins Gradle pluginの機能
       Gradleランタイムの管理
         Gradleの自動インストール/バージョン指定
         Gradle wrapperも指定可能
       ビルド手順「Invoke Gradle script」の提供
       コンソールに「実行されたGradleタスク」一覧のリ
        ンクを表示⇒ログの該当箇所にジャンプ




57
Gradle plugin: install




58
Gradle plugin: プロジェクト設定




59
Gradle plugin: コンソール




60
Gradleの便利プラグイン
    プロジェクトレポート
        http://gradle.monochromeroad.com/docs/use
         rguide/project_reports_plugin.html
    通知
        http://gradle.monochromeroad.com/docs/use
         rguide/announce_plugin.html
    Build Dashboard
        http://gradle.monochromeroad.com/docs/use
         rguide/buildDashboard_plugin.html
    Release
        https://github.com/townsfolk/gradle-release

    61
Gradleプラグイン、順調に増殖中
          http://wiki.
           gradle.org
           /display/G
           RADLE/Plu
           gins

62
Gradleの情報源
   Gradle 日本語ドキュメント(@literaliceさん)
       http://gradle.monochromeroad.com/docs/index.html
   ビルドツールGradle スタートアップガイドの紹介
       http://www.ntts.co.jp/publish/column/tec /java_03/in
        dex.html
   GVM:the Groovy enVironment Manager
       http://gvmtool.net/
       groovy/grails/gradle/griffon/vert.xに対応
   Gradleプロジェクトのソースコード
       https://github.com/gradle/gradle
       Gradleのdownloadにあるsrc.zipはビルドスクリプトがないの
        で、ソースコードリーディングにはこちらを参照するべし

    63
文字エンコーディング指定
   やり方はいろいろありますが、ビルドスクリプト
    中で指定するならこれがエレガントな方法
       http://mrhaki.blogspot.jp/2012/06/gradle
        -goodness-set-java-compiler.html
       タスクごとに指定
         compileJava.options.encoding = 'UTF-8‘
       タスクのタイプでまとめて指定
         tasks.withType(Compile){
            options.encoding = ‘UTF-8’ }


64
おすすめ書籍
   “Gradle Effective Implementation
    Guide” Hubert Klein Ikkink (mrhaki)
       http://mrhaki.blogspot.de/search/label/Gr
        adle%3AGoodness の人の本です




65
ありがとうございました




              http://nekofont.upat.jp/




66

More Related Content

What's hot

Markup Template Engine introduced Groovy 2.3
Markup Template Engine introduced Groovy 2.3Markup Template Engine introduced Groovy 2.3
Markup Template Engine introduced Groovy 2.3Uehara Junji
 
enterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summerenterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 SummerUehara Junji
 
New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1Uehara Junji
 
Jjug 20140430 gradle_basic
Jjug 20140430 gradle_basicJjug 20140430 gradle_basic
Jjug 20140430 gradle_basicTakuma Watabiki
 
Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Uehara Junji
 
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckIndy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckUehara Junji
 
Gradleどうでしょう
GradleどうでしょうGradleどうでしょう
GradleどうでしょうTakuma Watabiki
 
Groovy indy 20120222
Groovy indy 20120222Groovy indy 20120222
Groovy indy 20120222Nobuhiro Sue
 
Spring in-summer-gradle-hands on-withanswers
Spring in-summer-gradle-hands on-withanswersSpring in-summer-gradle-hands on-withanswers
Spring in-summer-gradle-hands on-withanswersTakuma Watabiki
 
groovy 2.1.0 20130118
groovy 2.1.0 20130118groovy 2.1.0 20130118
groovy 2.1.0 20130118Uehara Junji
 
ClojureでElectronアプリを作ろう
ClojureでElectronアプリを作ろうClojureでElectronアプリを作ろう
ClojureでElectronアプリを作ろうKazuhiro Hara
 
システム開発を前進させるためのGradle導入法
システム開発を前進させるためのGradle導入法システム開発を前進させるためのGradle導入法
システム開発を前進させるためのGradle導入法Takuma Watabiki
 
GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.Uehara Junji
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成shigeki_ohtsu
 
Jjug 20140430 gradle_advanced
Jjug 20140430 gradle_advancedJjug 20140430 gradle_advanced
Jjug 20140430 gradle_advancedMasatoshi Hayashi
 
OSS Product feat. Gradle
OSS Product feat. GradleOSS Product feat. Gradle
OSS Product feat. GradleYasuharu Nakano
 

What's hot (19)

Markup Template Engine introduced Groovy 2.3
Markup Template Engine introduced Groovy 2.3Markup Template Engine introduced Groovy 2.3
Markup Template Engine introduced Groovy 2.3
 
enterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summerenterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summer
 
New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1
 
Jjug 20140430 gradle_basic
Jjug 20140430 gradle_basicJjug 20140430 gradle_basic
Jjug 20140430 gradle_basic
 
Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait
 
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckIndy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
 
Gradleどうでしょう
GradleどうでしょうGradleどうでしょう
Gradleどうでしょう
 
Groovy indy 20120222
Groovy indy 20120222Groovy indy 20120222
Groovy indy 20120222
 
Spring in-summer-gradle-hands on-withanswers
Spring in-summer-gradle-hands on-withanswersSpring in-summer-gradle-hands on-withanswers
Spring in-summer-gradle-hands on-withanswers
 
GContractsの基礎
GContractsの基礎GContractsの基礎
GContractsの基礎
 
Jenkins と groovy
Jenkins と groovyJenkins と groovy
Jenkins と groovy
 
groovy 2.1.0 20130118
groovy 2.1.0 20130118groovy 2.1.0 20130118
groovy 2.1.0 20130118
 
ClojureでElectronアプリを作ろう
ClojureでElectronアプリを作ろうClojureでElectronアプリを作ろう
ClojureでElectronアプリを作ろう
 
システム開発を前進させるためのGradle導入法
システム開発を前進させるためのGradle導入法システム開発を前進させるためのGradle導入法
システム開発を前進させるためのGradle導入法
 
GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成
 
Jjug 20140430 gradle_advanced
Jjug 20140430 gradle_advancedJjug 20140430 gradle_advanced
Jjug 20140430 gradle_advanced
 
OSS Product feat. Gradle
OSS Product feat. GradleOSS Product feat. Gradle
OSS Product feat. Gradle
 
Grailsのススメ(仮)
Grailsのススメ(仮)Grailsのススメ(仮)
Grailsのススメ(仮)
 

Similar to Gws 20130315 gradle_handson

明日から使えるgradle
明日から使えるgradle明日から使えるgradle
明日から使えるgradlekimukou_26 Kimukou
 
Nseg20120929
Nseg20120929Nseg20120929
Nseg20120929hiro345
 
Groovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみようGroovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみようAkira Shimosako
 
TDD勉強会キックオフ for Java
TDD勉強会キックオフ for JavaTDD勉強会キックオフ for Java
TDD勉強会キックオフ for JavaYuta Kawadai
 
React Native GUIDE
React Native GUIDEReact Native GUIDE
React Native GUIDEdcubeio
 
TDC20111031_Groovy_Geb
TDC20111031_Groovy_GebTDC20111031_Groovy_Geb
TDC20111031_Groovy_GebNobuhiro Sue
 
Layout analyzerでのgroovyの利用について
Layout analyzerでのgroovyの利用についてLayout analyzerでのgroovyの利用について
Layout analyzerでのgroovyの利用についてkimukou_26 Kimukou
 
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
20150425 DroidKaigi つかえるGradleプロジェクトの作り方20150425 DroidKaigi つかえるGradleプロジェクトの作り方
20150425 DroidKaigi つかえるGradleプロジェクトの作り方Makoto Yamazaki
 
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2tamtam180
 
Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)tamtam180
 
GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化
GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化
GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化Shigeru Tsubota
 
はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入Yu Nobuoka
 
Introduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing DockerfilesIntroduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing DockerfilesYukiya Hayashi
 
G*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxG*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxNobuhiro Sue
 

Similar to Gws 20130315 gradle_handson (20)

明日から使えるgradle
明日から使えるgradle明日から使えるgradle
明日から使えるgradle
 
Grails 2.0.0.M1の話
Grails 2.0.0.M1の話 Grails 2.0.0.M1の話
Grails 2.0.0.M1の話
 
Nseg20120929
Nseg20120929Nseg20120929
Nseg20120929
 
Groovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみようGroovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみよう
 
G * magazine 0
G * magazine 0G * magazine 0
G * magazine 0
 
TDD勉強会キックオフ for Java
TDD勉強会キックオフ for JavaTDD勉強会キックオフ for Java
TDD勉強会キックオフ for Java
 
React Native GUIDE
React Native GUIDEReact Native GUIDE
React Native GUIDE
 
TDC20111031_Groovy_Geb
TDC20111031_Groovy_GebTDC20111031_Groovy_Geb
TDC20111031_Groovy_Geb
 
Capistrano
CapistranoCapistrano
Capistrano
 
Layout analyzerでのgroovyの利用について
Layout analyzerでのgroovyの利用についてLayout analyzerでのgroovyの利用について
Layout analyzerでのgroovyの利用について
 
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
20150425 DroidKaigi つかえるGradleプロジェクトの作り方20150425 DroidKaigi つかえるGradleプロジェクトの作り方
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
 
Gradle布教活動
Gradle布教活動Gradle布教活動
Gradle布教活動
 
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
 
Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)
 
GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化
GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化
GNS3上の仮想アプライアンス+GitLabRunner+BDDによるテスト自動化
 
Gradle handson
Gradle handsonGradle handson
Gradle handson
 
はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入
 
Introduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing DockerfilesIntroduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing Dockerfiles
 
MoteMote Compiler Plugin
MoteMote Compiler PluginMoteMote Compiler Plugin
MoteMote Compiler Plugin
 
G*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxG*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+Betamax
 

More from Nobuhiro Sue

Fuse Online Hands-on Guide
Fuse Online Hands-on GuideFuse Online Hands-on Guide
Fuse Online Hands-on GuideNobuhiro Sue
 
Fuse Online Hands-on Guide
Fuse Online Hands-on GuideFuse Online Hands-on Guide
Fuse Online Hands-on GuideNobuhiro Sue
 
Knative CloudEvents
Knative CloudEventsKnative CloudEvents
Knative CloudEventsNobuhiro Sue
 
JTF2018_B30_k8s_operator_nobusue
JTF2018_B30_k8s_operator_nobusueJTF2018_B30_k8s_operator_nobusue
JTF2018_B30_k8s_operator_nobusueNobuhiro Sue
 
DevLove k8s nobusue 20180711
DevLove k8s nobusue 20180711DevLove k8s nobusue 20180711
DevLove k8s nobusue 20180711Nobuhiro Sue
 
JSUG20171027-spfingboot-k8s-ocp
JSUG20171027-spfingboot-k8s-ocpJSUG20171027-spfingboot-k8s-ocp
JSUG20171027-spfingboot-k8s-ocpNobuhiro Sue
 
Light and shadow of microservices
Light and shadow of microservicesLight and shadow of microservices
Light and shadow of microservicesNobuhiro Sue
 
Gws 20141024 gradle_intro
Gws 20141024 gradle_introGws 20141024 gradle_intro
Gws 20141024 gradle_introNobuhiro Sue
 
Jjug 20140430 gradle_intro
Jjug 20140430 gradle_introJjug 20140430 gradle_intro
Jjug 20140430 gradle_introNobuhiro Sue
 
Gws 20140418 camel_groovy
Gws 20140418 camel_groovyGws 20140418 camel_groovy
Gws 20140418 camel_groovyNobuhiro Sue
 
20140329_kyon_kao_wedding_LT_Groovy
20140329_kyon_kao_wedding_LT_Groovy20140329_kyon_kao_wedding_LT_Groovy
20140329_kyon_kao_wedding_LT_GroovyNobuhiro Sue
 
Gws 20131018 vertx_handson(updated)
Gws 20131018 vertx_handson(updated)Gws 20131018 vertx_handson(updated)
Gws 20131018 vertx_handson(updated)Nobuhiro Sue
 
クラウド研究会 20120712 BaaS
クラウド研究会 20120712 BaaSクラウド研究会 20120712 BaaS
クラウド研究会 20120712 BaaSNobuhiro Sue
 
Letsgo developer 2012 Continuous Delivery
Letsgo developer 2012 Continuous DeliveryLetsgo developer 2012 Continuous Delivery
Letsgo developer 2012 Continuous DeliveryNobuhiro Sue
 
ぽんぽこバレー勉強会 20120427
ぽんぽこバレー勉強会 20120427ぽんぽこバレー勉強会 20120427
ぽんぽこバレー勉強会 20120427Nobuhiro Sue
 
Html5勉強会 20120423
Html5勉強会 20120423Html5勉強会 20120423
Html5勉強会 20120423Nobuhiro Sue
 
20111031 MobileWeb at TDC
20111031 MobileWeb at TDC20111031 MobileWeb at TDC
20111031 MobileWeb at TDCNobuhiro Sue
 
JJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and SpockJJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and SpockNobuhiro Sue
 
Letsgo sendai nobusue_20110528
Letsgo sendai nobusue_20110528Letsgo sendai nobusue_20110528
Letsgo sendai nobusue_20110528Nobuhiro Sue
 

More from Nobuhiro Sue (20)

Fuse Online Hands-on Guide
Fuse Online Hands-on GuideFuse Online Hands-on Guide
Fuse Online Hands-on Guide
 
Fuse Online Hands-on Guide
Fuse Online Hands-on GuideFuse Online Hands-on Guide
Fuse Online Hands-on Guide
 
Knative CloudEvents
Knative CloudEventsKnative CloudEvents
Knative CloudEvents
 
JTF2018_B30_k8s_operator_nobusue
JTF2018_B30_k8s_operator_nobusueJTF2018_B30_k8s_operator_nobusue
JTF2018_B30_k8s_operator_nobusue
 
DevLove k8s nobusue 20180711
DevLove k8s nobusue 20180711DevLove k8s nobusue 20180711
DevLove k8s nobusue 20180711
 
JSUG20171027-spfingboot-k8s-ocp
JSUG20171027-spfingboot-k8s-ocpJSUG20171027-spfingboot-k8s-ocp
JSUG20171027-spfingboot-k8s-ocp
 
Light and shadow of microservices
Light and shadow of microservicesLight and shadow of microservices
Light and shadow of microservices
 
Gws 20141024 gradle_intro
Gws 20141024 gradle_introGws 20141024 gradle_intro
Gws 20141024 gradle_intro
 
Jjug 20140430 gradle_intro
Jjug 20140430 gradle_introJjug 20140430 gradle_intro
Jjug 20140430 gradle_intro
 
Gws 20140418 camel_groovy
Gws 20140418 camel_groovyGws 20140418 camel_groovy
Gws 20140418 camel_groovy
 
20140329_kyon_kao_wedding_LT_Groovy
20140329_kyon_kao_wedding_LT_Groovy20140329_kyon_kao_wedding_LT_Groovy
20140329_kyon_kao_wedding_LT_Groovy
 
Gws 20140117 lt
Gws 20140117 ltGws 20140117 lt
Gws 20140117 lt
 
Gws 20131018 vertx_handson(updated)
Gws 20131018 vertx_handson(updated)Gws 20131018 vertx_handson(updated)
Gws 20131018 vertx_handson(updated)
 
クラウド研究会 20120712 BaaS
クラウド研究会 20120712 BaaSクラウド研究会 20120712 BaaS
クラウド研究会 20120712 BaaS
 
Letsgo developer 2012 Continuous Delivery
Letsgo developer 2012 Continuous DeliveryLetsgo developer 2012 Continuous Delivery
Letsgo developer 2012 Continuous Delivery
 
ぽんぽこバレー勉強会 20120427
ぽんぽこバレー勉強会 20120427ぽんぽこバレー勉強会 20120427
ぽんぽこバレー勉強会 20120427
 
Html5勉強会 20120423
Html5勉強会 20120423Html5勉強会 20120423
Html5勉強会 20120423
 
20111031 MobileWeb at TDC
20111031 MobileWeb at TDC20111031 MobileWeb at TDC
20111031 MobileWeb at TDC
 
JJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and SpockJJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and Spock
 
Letsgo sendai nobusue_20110528
Letsgo sendai nobusue_20110528Letsgo sendai nobusue_20110528
Letsgo sendai nobusue_20110528
 

Recently uploaded

【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 

Recently uploaded (8)

【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 

Gws 20130315 gradle_handson

  • 1. G*ワークショップZ Gradleハンズオン 2013.03.15(3.18更新) 須江信洋(@nobusue) http://d.hatena.ne.jp/nobusue https://www.facebook.com/nobuhiro.sue
  • 2. 自己紹介  須江 信洋(すえ のぶひろ)  Twitter: @nobusue  https://www.facebook.com/nobuhiro.sue  約10年ほどJavaEE関連の仕事をしてます  最近はPhoneGap(Cordova)とかがメイン  G*(Groovy関連技術)との関わり  JGGUGサポートスタッフ  「プログラミングGROOVY」執筆チーム  「Groovy イン・アクション」翻訳チーム  Groovyで作ったBot飼ってます(@hatena_groovy) 2
  • 3. agenda  Gradle概要 (thanks to 林さん)  Gradleインストール  Hello Gradle  Gradle Tools  Gradle Quickstart  Gradle Build Language概要  Ant integration  IDE integration  Jenkins integration  便利なGradleプラグイン紹介  参考情報 3
  • 4. 本日のサンプルコード  GitHubから入手してください  https://github.com/nobusue/GradleHandson  git clone https://github.com/nobusue/GradleHandson  より詳しい例はGradle公式サンプルを参照  http://www.gradle.org/downloads  gradle-1.4-all.zipの”samples”ディレクトリ 4
  • 5. Gradleインストール  前提  JDK1.5以上 (“java –version”で確認)  GVM利用  curl -s get.gvmtool.net | bash  gvm install gradle  詳細は http://gvmtool.net/ 参照  Windowsの場合はcygwinが必要  ZIPを展開  http://www.gradle.org/downloads  gradle-1.4-all.zipかgradle-1.4-bin.zip  適当なディレクトリに展開 ($GRADLE_HOME)  $GRADLE_HOME/bin にパスを通しておく 5
  • 6. 動作確認  gradle -v GVMでインストールした場合は ~/.gvm/gradle/1.4 以下に導入され、 ~/.gvm/gradle/current にシンボリックリンクが作成されます 6
  • 7. Hello Gradle  適当な作業ディレクトリを作成し、カレントディ レクトリを移動します  以下の内容で”build.gradle”を作成します task helloWorld << { println 'Hello world.' }  “gradle helloWorld” を実行します 7
  • 8. Hello Gradle解説 タスクにクロージャを追加 タスクの定義 ※ leftShift()の省略記法 task helloWorld << { println 'Hello world.' } Groovyのprintln文 8
  • 10. Gradle Tools  gradle command  gradle daemon  gradle-gui 10
  • 11. gradle command  gradle --help 11
  • 12. gradle commandの重要オプション  ログ関連  --quiet(-q) ログ出力を抑制  --info(-i) / --debug(-d)  --stacktrace(-s) / --full-stacktrace(-S)  ファイル/ディレクトリ指定  --build-file(-b) build.gradle以外  --project-dir(-p) カレントディレクトリ以外  テスト  --dry-run(-m) タスクの実行順序のみ確認 12
  • 13. 環境まわりのまとめ  環境変数  JAVA_OPTS ⇒JVM全体に影響  GRADLE_OPTS ⇒gradleのみ影響  初期化スクリプト(init scripts)  ビルドの開始前に実行される  ~/.gradle/init.gradle  ~/.gradle/init.d/*.gradle  $GRADLE_HOME/init.d/*.gradle  --init-script(-I)で指定することも可能 13
  • 14. gradle daemon  gradleのプロセスを常駐して起動を高速化  起動  gradle --daemon helloWorld  停止  gradle --stop  起動済みのプロセスを使わない  gradle –no-daemon helloWorld  常にdaemonを使う場合は以下いずれか  alias gradled=‘gradle --daemon’  export GRADLE_OPTS= “-Dorg.gradle.daemon=true” 14
  • 15. gradle-gui  gradle --gui 15
  • 16. Gradle Quickstart  Java project  Groovy project  Web project 16
  • 17. Javaプロジェクトのレイアウト . Mavenと同様の規約に従って ├── build.gradle └── src ├── main │ ├── java プロダクトコードとテストコードを │ │ │ │ └── org └── gradle 配置 │ │ └── Person.java │ └── resources │ └── org │ └── gradle │ └── resource.xml └── test ├── java │ └── org │ └── gradle │ └── PersonTest.java └── resources └── org └── gradle └── test-resource.xml 17
  • 18. Javaプロジェクトのビルドスクリプト(抜粋) apply plugin: 'java' Javaプラグインを適用 repositories { mavenCentral() 依存性解決にMavenリポジトリを利用 } プロダクトコードのコンパイル時の依存先 dependencies { compile( group: 'commons-collections', name: 'commons-collections', version: '3.2') testCompile( テストコードのコンパイル時の依存先 group: 'junit', name: 'junit', version: '4.+') } 18
  • 19. Javaプラグインが追加するタスク Build tasks ----------- assemble - Assembles the outputs of this project. build - Assembles and tests this project. buildDependents - Assembles and tests this project and all projects that depend on it. buildNeeded - Assembles and tests this project and all projects it depends on. classes - Assembles the main classes. clean - Deletes the build directory. jar - Assembles a jar archive containing the main classes. testClasses - Assembles the test classes. Documentation tasks ------------------- javadoc - Generates Javadoc API documentation for the main source code. 19
  • 20. Javaプラグインが追加するタスク Upload tasks ------------ uploadArchives - Uploads all artifacts belonging to configuration ':archives' Verification tasks ------------------ check - Runs all checks. test - Runs the unit tests. Rules ----- Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration. Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration. Pattern: clean<TaskName>: Cleans the output files of a task. 20
  • 21. Groovyプロジェクトのレイアウト . ├── build.gradle └── src ├── main │ ├── groovy │ │ └── org │ │ └── gradle │ │ └── Person.groovy │ └── resources │ ├── resource.txt │ └── script.groovy └── test ├── groovy │ └── org │ └── gradle │ └── PersonSpec.groovy └── resources ├── testResource.txt └── testScript.groovy 21
  • 22. Groovyプロジェクトのビルドスクリプト Groovyプラグインを適用 apply plugin: 'groovy' repositories { 依存性解決にMavenリポジトリを利用 mavenCentral() } プロダクトコードのコンパイル時の依存先 dependencies { compile 'org.codehaus.groovy:groovy-all:2.0.5' testCompile "org.spockframework:spock-core:0.7-groovy-2.0" } テストコードのコンパイル時の依存先 22
  • 23. Groovyプラグインが追加するタスク Documentation tasks ------------------- javadoc - Generates Javadoc API documentation for the main source code. Documentation tasks groovydoc - Generates Groovydoc API documentation for the main source code. GroovyプラグインはJavaプラグインを拡張して作られているため、 Javaプラグインが提供するタスクはそのまま利用可能 (ただし、一部のタスクはGroovy用に機能拡張されている) 23
  • 24. Webappプロジェクトのレイアウト . ├── build.gradle └── src └── main ├── java │ └── org │ └── gradle │ └── sample │ └── Greeter.java ├── resources │ └── greeting.txt └── webapp └── index.jsp 24
  • 25. Webappプロジェクトのビルドスクリプト Warプラグインを適用 apply plugin: 'war' apply plugin: 'jetty' Jettyプラグインを利用して ビルドスクリプト上でwarを実行可能 repositories { mavenCentral() } 依存性解決にMavenリポジトリを利用 dependencies { compile group: 'commons-io', name: 'commons-io', version: '1.4' compile group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar' } プロダクトコードのコンパイル時の依存先 httpPort = 8080 stopPort = 9451 stopKey = 'foo' Jettyプラグインのパラメータ 25
  • 26. Webappプラグインが追加するタスク Build tasks ----------- war - Generates a war archive with all the compiled classes, the web-app content and the libraries. Web application tasks --------------------- jettyRun - Uses your files as and where they are and deploys them to Jetty. jettyRunWar - Assembles the webapp into a war and deploys it to Jetty. jettyStop - Stops Jetty. WebappプラグインはJavaプラグインを拡張して作られているため、 Javaプラグインが提供するタスクはそのまま利用可能 (ただし、一部のタスクはWebapp用に機能拡張されている) 26
  • 27. Gradle Build Language概要  Gradle DSL  Gradle Domain Objects 27
  • 28. Gradle DSLのエントリーポイント  Gradleビルド言語リファレンス  http://gradle.monochromeroad.com/docs/ dsl/index.html 28
  • 29. タスク定義 task('hello') << { task(hello) << { println "hello" println "hello" } } task('copy', type: Copy) { task(copy, type: Copy) { from(file('srcDir')) from(file('srcDir')) into(buildDir) into(buildDir) } } task copy(type: Copy) { description = 'Copies the resource directory to the target directory.' from 'resources' into 'target' include('**/*.txt', '**/*.xml', '**/*.properties') } 29
  • 30. デフォルトタスク defaultTasks 'clean', 'run' task clean << { println 'Default Cleaning!' } task run << { println 'Default Running!' } task other << { println "I'm not a default task!" } 30
  • 31. タスク依存関係(task利用) task taskX << { println 'taskX' } task taskY << { println 'taskY' } taskX.dependsOn taskY タスク名でtaskオブジェクトを参照 31
  • 32. タスク依存関係(クロージャ利用) task taskX << { println 'taskX' } taskX.dependsOn { tasks.findAll { task -> task.name.startsWith('lib') } } task lib1 << { println 'lib1' taskのコレクションを返すクロージャ } task lib2 << { println 'lib2' } task notALib << { println 'notALib' } 32
  • 33. description/グループ化 def taskGroup = 'base‘ task first(description: 'Base task', group: taskGroup) << { println "I am first task" } groupを指定 task second(dependsOn: first, description: 'Secondary task', group: taskGroup) << { println "I am second task" } 33
  • 34. 動的タスク定義 4.times { counter -> task "task${counter}" << { println "${counter+1}番目の動的タスクです" } } 34
  • 35. 条件分岐 task "OsDependTask" << { def os = System.getProperty("os.name") if(os.contains("Windows")) { println "Windows用の処理" } else if(os.contains("Mac OS")) { println "Mac OS用の処理" } else { println "Linux/Unix用の処理" } } 35
  • 36. Gradleの代表オブジェクト  org.gradle.api.Project  ビルドスクリプト(build.gradle)に対応  中核となるオブジェクト  ビルドスクリプト内では暗黙的に、もしくはproject プロパティで参照 36
  • 37. Gradleの代表オブジェクト  org.gradle.api.invocation.Gradle  実行中のビルドエンジンに対応  初期化時の情報や、環境情報を保持  Project.getGradle() で取得可能 37
  • 38. Gradleの代表オブジェクト  org.gradle.api.initialization.Settings  settings.gradleに対応  マルチプロジェクト構成時にプロジェクト階層の情 報を保持 38
  • 39. 便利メソッド/プロパティ  file()  相対/絶対パス、Fileオブジェクト、URLなど  PathValidationでいろいろ判定可能  files()  ファイルのコレクション(filter可能)  引数としてファイルを返すtaskを渡せる  fileTree()  ファイルのツリー階層をトラバース(visit)可能  Antのpathelement式でinclude/exclude可能  logger  SLF4J Loggerのインスタンス  標準出力への出力はQUIETレベルにリダイレクト 39
  • 40. 拡張プロパティ  Gradleのドメインモデルにプロパティを追加する 際には、extプロパティ(extブロック)を使うこと  Gradle-1.0M9からこちらが強く推奨されています  現在は互換性のため未定義のプロパティがあってもエ ラーにならないが、警告が出ます  ローカル変数(def)と異なり、ドメインモデルのラ イフサイクル全体で利用できます  詳細はこちらの「13.4.2. 拡張プロパティ」を参照  http://gradle.monochromeroad.com/docs/use rguide/writing_build_scripts.html 40
  • 41. Ant integration  Antタスクの利用  Antビルド定義の利用 41
  • 42. AntからGradleへ  Gradleは既存のAnt資産を活用できる  Antのbuild.xmlをそのまま読み込んで実行可能  Antターゲット=Gradleタスク  AntタスクをGradleから直接利用可能  GroovyのAntBuilderが組み込まれている  AntタスクとGradleタスクを共存することも可能  相互に依存するタスクも定義できる  AntタスクをGradleから拡張することもできる  Gradleは「Better Ant」としても使える  Mavenとの大きな違い  Antから段階的にGradleへ移行できる 42
  • 43. GradleでAntタスクを利用 task hello << { ant.echo('Antタスクの実行') } 43
  • 44. GradleでAntのビルド定義を利用 [build.gradle] ant.importBuild 'build.xml' [build.xml] <project> <target name="hello"> <echo>Antターゲットの実行</echo> </target> </project> 44
  • 45. IDE integration  IntelliJ IDEA  Eclipse 45
  • 46. IntelliJ IDEA  Gradle -> IntelliJ  gradle IntelliJ pluginを利用  apply plugin: 'idea'  IDEA固有リソースを生成  IntellJ Gradle plugin(JetGradle)  Preferences -> Plugins -> Gralde  ウィンドウ右端の「JetGradle」を開いてみよう! 46
  • 47. IntelliJ IDEA: Gradle build confing 47
  • 49. Eclipse  Gradle -> Eclipse  gradle Eclipse pluginを利用  apply plugin: ‘eclipse'  Eclipse固有リソースを生成  ただし、使いこなすにはいろいろ癖が・・・  Eclipse Gradle plugin  STSの一部として提供  http://dist.springsource.com/release/TO OLS/gradle 49
  • 52. Jenkins integration  Gradle wrapper  Jenkis Gradle plugin 52
  • 53. Jenkinsとの統合 - Gradle  Gradle wrapperを利用  JDKさえ導入されていれば、Gradleを自動でイン ストールして実行してくれる  Jenkins上では汎用コマンドとして実行すればよい  Gradle wrapperは、CI用途に限らず、 開発者の環境構築負荷軽減にも有用 53
  • 54. Gradle wrapper [build.gradle] task wrapper(type: Wrapper) { gradleVersion = '1.4' } Gradle導入済の環境で"gradle wrapper"を実行 すると、Gradleのブートストラップ(gradlew)が生成される バージョン管理 システム 54
  • 57. Jenkins Gradle plugin  Jenkins Gradle pluginの機能  Gradleランタイムの管理  Gradleの自動インストール/バージョン指定  Gradle wrapperも指定可能  ビルド手順「Invoke Gradle script」の提供  コンソールに「実行されたGradleタスク」一覧のリ ンクを表示⇒ログの該当箇所にジャンプ 57
  • 61. Gradleの便利プラグイン  プロジェクトレポート  http://gradle.monochromeroad.com/docs/use rguide/project_reports_plugin.html  通知  http://gradle.monochromeroad.com/docs/use rguide/announce_plugin.html  Build Dashboard  http://gradle.monochromeroad.com/docs/use rguide/buildDashboard_plugin.html  Release  https://github.com/townsfolk/gradle-release 61
  • 62. Gradleプラグイン、順調に増殖中 http://wiki. gradle.org /display/G RADLE/Plu gins 62
  • 63. Gradleの情報源  Gradle 日本語ドキュメント(@literaliceさん)  http://gradle.monochromeroad.com/docs/index.html  ビルドツールGradle スタートアップガイドの紹介  http://www.ntts.co.jp/publish/column/tec /java_03/in dex.html  GVM:the Groovy enVironment Manager  http://gvmtool.net/  groovy/grails/gradle/griffon/vert.xに対応  Gradleプロジェクトのソースコード  https://github.com/gradle/gradle  Gradleのdownloadにあるsrc.zipはビルドスクリプトがないの で、ソースコードリーディングにはこちらを参照するべし 63
  • 64. 文字エンコーディング指定  やり方はいろいろありますが、ビルドスクリプト 中で指定するならこれがエレガントな方法  http://mrhaki.blogspot.jp/2012/06/gradle -goodness-set-java-compiler.html  タスクごとに指定  compileJava.options.encoding = 'UTF-8‘  タスクのタイプでまとめて指定  tasks.withType(Compile){ options.encoding = ‘UTF-8’ } 64
  • 65. おすすめ書籍  “Gradle Effective Implementation Guide” Hubert Klein Ikkink (mrhaki)  http://mrhaki.blogspot.de/search/label/Gr adle%3AGoodness の人の本です 65
  • 66. ありがとうございました http://nekofont.upat.jp/ 66