Using the all-open plugin in Gradle

The all-open plugin for Gradle can be used as follows:

buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
apply plugin: "kotlin-allopen"

We have to add the plugin artifact in the buildscript dependencies section of the Gradle file. We can also enable the all-open plugin using the plugins section, as follows:

plugins {
id "org.jetbrains.kotlin.plugin.allopen" version "1.2.41"
}

Following this, we can specify a list of annotations that will make our classes open and accessible:

allOpen {
annotation("javax.ejb.Stateless")
}

We can specify multiple annotations using the annotations section in the allOpen plugin:

 allOpen {
annotations("javax.ejb.Stateless",
"javax.inject.Inject")
}

We can then define custom annotations. The all-open compiler plugin is used to open the classes that are annotated with the custom annotations:

allOpen {
annotation("org.rao.kotlin.javaee.Annotation")
}


@org.rao.kolin.javaee.Annotation
annotation class MyAnnotation

@MyAnnotation
class Person{ }

Now, the Person class will be open.

The MyAnnotation class is annotated with a meta-annotation—@org.rao.kolin.javaee.Annotation. It is now an all-open plugin annotation that can be used in other classes to make them open and accessible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset