Gradle 4.9 の新しいタスク定義 API と Gradle Kotlin DSL 1.0 RC での対応
Gradle 4.9 の新しいタスク定義 API
Gradle 4.9 で、新しいタスク定義 API が導入されました。 まだ incubating です。
パフォーマンス向上のため、タスクの設定を遅延実行する、というのがこの新しい API の導入の目的のようです。 古い API では Task
インスタンスをすぐに生成していたのを、新 API ではまず Provider<Task>
を生成して、必要になった段階で Task
インスタンスを生成する、という形になります。
Gradle Kotlin DSL 1.0 RC での対応
ちょうど昨日 Gradle 4.10 がリリースされましたね! めでたい!
Gradle 4.10 is out! https://t.co/wmo5e8eb8y
— Gradle (@gradle) 2018年8月27日
⚡️ Incremental @java compilation by default
📤 Periodic Gradle cache cleanup
🚀 @Kotlin DSL 1.0 RC
📦 Plugins DSL supports SNAPSHOT versions pic.twitter.com/5oNXRYJgra
Gradle 4.10 には Gradle Kotlin DSL 1.0-RC3 が載っており、Kotlin DSL の方でも新しいタスク定義 API がサポートされています。
Release 1.0-RC3 · gradle/kotlin-dsl · GitHub
- introducing the new existing and registering delegated properties designed specifically with configuration avoidance in mind which expose
NamedDomainObjectProvider<T>
instead of the container element type.
下記のように使用できます。
// 既存タスクの設定。 val test by tasks.existing(Test::class) { ... } // 新規タスクの宣言と設定。 val jacocoMerge by tasks.registering(JacocoMerge::class) { ... }
使ってみた
早速使ってみました。
Update Gradle (version 4.10) by nobuoka · Pull Request #13 · nobuoka/wd-image-processor · GitHub
小さいプロジェクトなので特にパフォーマンスの向上などは感じられませんが、移行自体は苦労なくできます。