Kotlin-spring compiler plugin
The kotlin-spring compiler plugin configures Kotlin projects for Spring by automatically making certain Spring-annotated classes and members open at compile time.
This plugin is a preconfigured wrapper around the all-open plugin and behaves the same way: it makes a class and its members open when they have a Spring annotation. You can use both all-open and kotlin-spring in the same project.
Supported Spring annotations
The plugin makes a class and its members open when the class has any of the following Spring annotations:
The plugin also supports meta-annotations. Classes annotated with @Configuration, @Controller, @RestController, @Service, or @Repository also become open, because Spring meta-annotates these annotations with @Component.
Apply the plugin
Gradle
Add the kotlin-spring plugin in the plugins {} block of your build.gradle(.kts) file:
Maven
In Maven, support for the kotlin-spring plugin is provided by the kotlin-maven-allopen plugin. Add it to your pom.xml file:
Use the kotlin-spring plugin
When you apply the plugin, the compiler treats classes with common Spring annotations as open at compile time. You can write these classes without adding the open keyword:
What's next?
For JPA entities that require a zero-argument constructor, use the
kotlin-jpaplugin, which configures theno-argplugin with JPA annotations such as@Entity,@Embeddable, and@MappedSuperclass.Create your first Spring Boot application using the Get started with Spring Boot and Kotlin tutorial.