好きな言語:
好きなIDE:
Gradle Wrapperのアップデート
./gradlew wrapper --gradle-version=2.13
apply plugin: 'application'
mainClassName = 'samples.HelloWorld'
repositories {
jcenter()
}
dependencies {
testCompile "junit:junit:4.12"
}
import org.gradle.api.plugins.*
import org.gradle.script.lang.kotlin.*
apply<ApplicationPlugin>()
configure<ApplicationPluginConvention> {
mainClassName = "samples.HelloWorld"
}
repositories {
jcenter()
}
dependencies {
"testCompile"("junit:junit:4.12")
}
その他、Gradleについては Gradleで始めるGroovy expand でも紹介しているので、参考にしてください。
その他に
つまり、
すっきりしているbuild.gradleほど
よりGradle Pluginに依存している
Gradleはタスクを組み合わせて、DAG(有向非循環グラフ)を作る
後に実行したいタスク名.mustRunAfter 先に実行するタスク名
後に実行したいタスク名.shouldRunAfter 先に実行するタスク名
後始末が必要なタスク名.finalizedBy 後始末を行うタスク名
タスクのinputs, outputsプロパティのfileやdirへ、ファイルパスやディレクトリパスを指定すると、更新に応じてタスクをスキップする事が出来る。
outputs.upToDateWhen{ true }とすると常に最新として扱われるので、inputsに更新があった場合のみ、タスクが実行されるようになる。
参考:
タスクが多くなってbuild.gradleが見づらくなってきた。
-> build.gradleを分割してみましょう。
build.gradleを以下のように記載。
apply from: 'gradle/front.gradle'
// URLも利用可能
apply from: 'http://example.com/extra.gradle'
// releaseのみ含めたい場合
if (ext.env == 'release') {
apply from: 'gradle/release.gradle'
}
そういったタスクをいかに楽して自動化するか?
もしかしてVBですかーッ?
またまた、ご冗談を(AA略
オレオレTaskクラスは、Groovyだけでなく、もちろんJavaや他のJVM言語でも書けます!
タスクをクラスにして別のプロジェクトとして切り出す
-> Gradle Plugin
src/main/resources/META-INF/gradle-plugins/
のpropertiesファイルにあるPluginのクラスを見つけるapply
メソッドを探すREPL(groovysh)を使いたい
groovy scriptをgradleから実行したい
build時にGitのハッシュを取得する
Dockerfileやdocker-compose.ymlを生成したり、dockerのコマンドをdocker-javaで実行する
Nebula Plugin