# All-open compiler plugin In Kotlin, classes and their members are `final` by default. This can cause issues with frameworks and libraries that rely on subclassing and runtime proxies, which require classes to be `open`. The `all-open` compiler plugin makes classes and their members `open` at compile time without requiring the `open` keyword. You need to create an annotation, add it to the plugin options, and annotate the classes you want to make `open`: ```KOTLIN @YourAnnotation class MyService { // This class and all its members are open now fun doWork() { /* ... */ } } ``` If a class or any of its superclasses is annotated with a configured annotation, the class and its members become `open`. Note: For Spring applications with Kotlin, you can use the [kotlin-spring compiler plugin](kotlin-spring-plugin.html). It makes a class and its members `open` when they have a Spring annotation. ## Declare an annotation The `all-open` plugin only processes classes marked with an annotation that you register in its configuration. So before enabling the plugin, declare an annotation to mark the classes you want to make `open`. For example, `AllOpenMarker`: ```KOTLIN package com.example annotation class AllOpenMarker ``` ## Apply the plugin ### Gradle To enable the plugin, add it to the `plugins {}` block of your `build.gradle(.kts)` file: Kotlin: ```KOTLIN // build.gradle.kts plugins { kotlin("jvm") version "2.4.21" kotlin("plugin.allopen") version "2.4.21" } ``` Groovy: ```GROOVY // build.gradle plugins { id "org.jetbrains.kotlin.jvm" version "2.4.21" id "org.jetbrains.kotlin.plugin.allopen" version "2.4.21" } ``` Then specify the annotation you declared earlier (for example, `com.example.AllOpenMarker`) or a list of annotations that make classes `open`: Kotlin: ```KOTLIN allOpen { annotation("com.example.AllOpenMarker") // You can specify multiple annotations: // annotations("com.example.AllOpenMarker", "com.anotherPackage.OtherAnnotation") } ``` Groovy: ```GROOVY allOpen { annotation("com.example.AllOpenMarker") // You can specify multiple annotations: // annotations("com.example.AllOpenMarker", "com.anotherPackage.OtherAnnotation") } ``` ### Maven Add the plugin in your `pom.xml` file: ```XML 2.4.21 kotlin-maven-plugin org.jetbrains.kotlin ${kotlin.version} all-open org.jetbrains.kotlin kotlin-maven-allopen ${kotlin.version} ``` ## Use the `all-open` plugin If a class or any of its superclasses has the `com.example.AllOpenMarker` annotation you created, the class and all its members become `open`: ```KOTLIN package com.example @AllOpenMarker class TestClass { // This class and all its members are open } ``` The plugin also works with meta-annotations. If you mark another annotation with `@AllOpenMarker`, all classes and members annotated with it become `open`: ```KOTLIN package com.example // An annotation marked with a previously created annotation @AllOpenMarker annotation class AnotherAllOpenMarker @AllOpenMarker class NewClass { // This class and all its members are open } @AnotherAllOpenMarker class AnotherClass { // This class and all its members are open as well } ``` ## What's next? * For Spring applications, use the [kotlin-spring plugin](kotlin-spring-plugin.html), a preconfigured wrapper that makes classes with Spring annotations `open`. * For JPA entities, use the [kotlin-jpa plugin](kotlin-jpa-plugin.html), which makes entities `open` and generates zero-argument constructors for them. * Explore the source code of the [all-open compiler plugin](https://github.com/JetBrains/kotlin/tree/master/plugins/allopen).