Last week I decided to raffle a copy of my book (see Twitter) and I wrote a small Spring Boot Command Line Runner to raffle the retweeting winner as one does (see raffle-by-retweet, feel free to reuse this).
I wrote the application in Kotlin. Notice the use of @ConfigurationProperties
in my application:
The lateinit
attributes are not as nice as I want them to be, but I heard support for data
-classes is coming. Anyway. A super useful thing with those configuration property classes are the metadata that can be generated for your IDE of choice, see Configuration Metadata. In a Java application it’s enough to add org.springframework.boot:spring-boot-configuration-processor
as compile time dependency respectively as annotationProcessor
dependency in a Gradle build.
For Kotlin, you have to use the kotlin-kapt
-plugin. It takes care of annotation processing in Kotlin and Spring Boots annotation processor has to be declared in its scope like this:
apply plugin: 'kotlin-kapt' dependencies { // Other dependencies omitted kapt("org.springframework.boot:spring-boot-configuration-processor") } |
To make IDEA recognize the generated sources (and also use the same folders for classes as the Gradle build), you can this as well:
apply plugin: 'idea' idea { module { def kaptMain = file("${project.buildDir}/generated/source/kapt/main") sourceDirs += kaptMain generatedSourceDirs += kaptMain outputDir file("${project.buildDir}/classes/main") testOutputDir file("${project.buildDir}/classes/test") } } |
Find the full build script here.
No comments yet
Post a Comment