読者です 読者をやめる 読者になる 読者になる

KZKY memo

自分用メモ.

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"]
}