Kotlin 1.2.0 + Spring: create Web Application (4 of 4)


Here, it continues from Kotlin 1.2.0 + Spring: create Web Application (3 of 4).

Write Gradle in Kotlin

Write build.gradle in Kotlin

build.gradle is also written in Kotlin. In the same directory with build.gradle, create build.gradle.kts and write as follows.

Then, delete build.gradle. Execute ./gradlew clean && ./gradlew bootrun, then the server will work.

In the earlier version Gradle than 4.0, we must add one line into settings.gradle. From Kotlin DSL v0.9.0, it doesn’t need rootProject.buildFileName for writing build.gradle.kts. Kotlin DSL v0.9.0 is included in Gradle 4.0.

Write settings.gradle in Kotlin

Kotlin DSL v0.13.1 can also write settings.gradle.kts. Gradle 4.4 RC1 includes it. In Intellij IDEA, Kotlin plugin of the version 1.1.60-eap-43 supports it.

Rename settings.gradle to settings.gradle.kts. In settings.gradle, both single and double quotes represents string, but only double quotes represents string in Kotllin. Then, change rootProject.name value.

Before rootProject.name = 'myapp'
After rootProject.name = “myapp”

The project is publicized in GitHub: Kotlin 1.2.0 Spring Sample.