All-open compiler plugin
Kotlin has classes and their members
final by default, which makes it inconvenient to use frameworks and libraries such as Spring AOP that require classes to be
open. The all-open compiler plugin adapts Kotlin to the requirements of those frameworks and makes classes annotated with a specific annotation and their members open without the explicit
For instance, when you use Spring, you don't need all the classes to be open, but only classes annotated with specific annotations like
@Service. All-open allows to specify such annotations.
We provide all-open plugin support both for Gradle and Maven with the complete IDE integration.
Add the plugin artifact to the build script dependencies and apply the plugin:
As an alternative, you can enable it using the
Then specify the list of annotations that will make classes open:
If the class (or any of its superclasses) is annotated with
com.my.Annotation, the class itself and all its members will become open.
It also works with meta-annotations:
MyFrameworkAnnotation is annotated with the all-open meta-annotation
com.my.Annotation, so it becomes an all-open annotation as well.
Here's how to use all-open with Maven:
Please refer to the Gradle section for the detailed information about how all-open annotations work.
If you use Spring, you can enable the kotlin-spring compiler plugin instead of specifying Spring annotations manually. The kotlin-spring is a wrapper on top of all-open, and it behaves exactly the same way.
As with all-open, add the plugin to the build script dependencies:
Or using the Gradle plugins DSL:
In Maven, the
spring plugin is provided by the
kotlin-maven-allopen plugin dependency, so to enable it:
The plugin specifies the following annotations:
Thanks to meta-annotations support, classes annotated with
@Repository are automatically opened since these annotations are meta-annotated with
Of course, you can use both
kotlin-spring in the same project.
Note that if you use the project template generated by the start.spring.io service, the
kotlin-spring plugin will be enabled by default.
All-open compiler plugin JAR is available in the binary distribution of the Kotlin compiler. You can attach the plugin by providing the path to its JAR file using the
Xplugin kotlinc option:
You can specify all-open annotations directly, using the
annotation plugin option, or enable the "preset". The presets available now for all-open are