Kotlin for Enterprise Applications using Java EE
上QQ阅读APP看书,第一时间看更新

Using the no-org plugin in Gradle

Add the plugin in the buildscript dependencies section in the Gradle file:

buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
}
}

apply plugin: "kotlin-noarg"

Alternatively, we can enable the no-arg plugin using Gradle as follows:

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

We can then specify the list of annotations in the plugin section. The no-arg plugin generates the default constructor for the classes that are annotated with the annotations that we specified in the noArg annotation section of the plugin:

noArg {
annotation("org.rao.kotlin.javaee.MyClass")
}

If we want to execute the initialization of member variables from the default constructor, we can use the invokeInitializers plugin option:

noArg {
invokeInitializers = true
}