Kotlin Help

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:

@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.

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:

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:

// build.gradle.kts plugins { kotlin("jvm") version "2.4.21" kotlin("plugin.allopen") version "2.4.21" }
// 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:

allOpen { annotation("com.example.AllOpenMarker") // You can specify multiple annotations: // annotations("com.example.AllOpenMarker", "com.anotherPackage.OtherAnnotation") }
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:

<properties> <kotlin.version>2.4.21</kotlin.version> </properties> <plugin> <artifactId>kotlin-maven-plugin</artifactId> <groupId>org.jetbrains.kotlin</groupId> <version>${kotlin.version}</version> <configuration> <compilerPlugins> <plugin>all-open</plugin> </compilerPlugins> <pluginOptions> <!-- Add multiple lines for multiple annotations --> <option>all-open:annotation=com.example.AllOpenMarker</option> <option>all-open:annotation=com.anotherPackage.OtherAnnotation</option> </pluginOptions> </configuration> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-allopen</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> </plugin>

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:

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:

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?

21 October 2026