官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 故城县| 什邡市| 濮阳市| 改则县| 黄梅县| 陈巴尔虎旗| 六枝特区| 阳信县| 太保市| 宜宾县| 长丰县| 永登县| 福鼎市| 志丹县| 白山市| 宣恩县| 惠安县| 色达县| 乌苏市| 哈尔滨市| 兴业县| 灯塔市| 南安市| 获嘉县| 米林县| 灵武市| 聂拉木县| 武功县| 高阳县| 茂名市| 枣庄市| 白水县| 湖南省| 呼伦贝尔市| 巨野县| 丰原市| 宁强县| 资源县| 凤凰县| 绥化市| 大新县|