Gradle 基本
Installation (Ubuntu14.04)
最新版を入れる
$ sudo add-apt-repository ppa:cwchien/gradle
$ sudo apt-get update
$ sudo apt-get install gradle
超基本構文
task taskName { processing somthing } task taskName << { // equivalent to task X {doLast { } } ) processing somthing } task taskX(dependsOn taskY) << { processing somthing }
Property
独自propertyの定義
task myTask { ext.myProperty = "myValue" } task printTaskProperties << { println myTask.myProperty }
Samples
hello world
task hello { hello.doFirst { println 'Hello Venus' } doLast { println 'Hello world!' } }
add property to project
task myTask { ext.myProperty = "myValue" } task printTaskProperties << { println myTask.myProperty }
some functions
task upper << { String someString = 'mY_nAmE' println "Original: " + someString println "Upper case: " + someString.toUpperCase() }
dependency
task taskX(dependsOn: 'taskY') << { println 'taskX' } task taskY << { println 'taskY' }
dynamic task
4.times { counter -> task "task$counter" << { println "I'm task number $counter" } } // manipulate dependency between tasks task0.dependsOn task2, task3
default task
defaultTasks 'clean', 'run' task clean << { println 'Default Cleaning!' } task run << { println 'Default Running!' }
DAG
task distribution << { println "We build the zip with version=$version" } task release(dependsOn: 'distribution') << { println 'We release now' } gradle.taskGraph.whenReady {taskGraph -> if (taskGraph.hasTask(release)) { version = '1.0' } else { version = '1.0-SNAPSHOT' } }
show properties
task showProperties << { getProperties().each{ println "${it.getKey()}, ${it.getValue()}" } }
show tasks
task showTasks << { tasks.each { println it } println "" println tasks["run"] }
URLs
これをよめばある程度わかるはず
- Chapter6. http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html
- Chapter7. http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html
- Chapter8. http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
- Chapter13. http://www.gradle.org/docs/current/userguide/writing_build_scripts.html
- Chapter15. http://www.gradle.org/docs/current/userguide/more_about_tasks.html
- Chapter25. http://www.gradle.org/docs/current/userguide/scala_plugin.html
- Chapter45. http://www.gradle.org/docs/current/userguide/application_plugin.html
- Chapter51. http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
- Chapter56. http://www.gradle.org/docs/current/userguide/build_lifecycle.html
- Chapter57. http://www.gradle.org/docs/current/userguide/multi_project_builds.html
- Chapter58. http://www.gradle.org/docs/current/userguide/custom_tasks.html
- http://www.gradle.org/docs/current/dsl/