Write build.gradle and settings.gradle in Kotlin


I summarized the way to write build.gradle and settings.gradle in Kotlin.

Environment

  • Kotlin 1.2.0
  • Gradle 4.4 RC 5

Required

Gradle 3.0 M1 or higher is required for writing build.gradle in Kotlin, Gradle 4.4 RC1 or higher is required for writing settings.gradle.kts in Kotlin.

build.gradle

Here is a sample in Kotlin.

From Gradle 4.0 RC1, it is not needed because Kotlin DSL 0.9.0 is included, but when you use earlier Gradle, you have to write the following line into settings.gradle.

filter example is in Spring Boot のアプリケーションを AWS EC2 にデプロイする手順.

settings.gradle

This is not so different from one in Groovy.

Intellij IDEA consider rootProject as the interface without getName method, so I cast it to ProjectDescriptor. It can be also built successfully without cast.