No-arg compiler plugin
The no-arg compiler plugin generates an additional zero-argument constructor for classes with a specific annotation.
The generated constructor is synthetic, so it can't be directly called from Java or Kotlin, but it can be called using reflection.
This allows the Java Persistence API (JPA) to instantiate a class although it doesn't have the zero-parameter constructor from Kotlin or Java point of view (see the description of kotlin-jpa
plugin below).
In your Kotlin file
Add new annotations to mark the code that needs a zero-argument constructor:
Gradle
Add the plugin using Gradle's plugins DSL:
Then specify the list of no-arg annotations that must lead to generating a no-arg constructor for the annotated classes:
Enable invokeInitializers
option if you want the plugin to run the initialization logic from the synthetic constructor. By default, it is disabled.
Maven
JPA support
As with the kotlin-spring
plugin wrapped on top of all-open
, kotlin-jpa
is wrapped on top of no-arg
. The plugin specifies @Entity
, @Embeddable
, and @MappedSuperclass
no-arg annotations automatically.
Add the plugin using the Gradle plugins DSL:
In Maven, enable the jpa
plugin:
Command-line compiler
Add the plugin JAR file to the compiler plugin classpath and specify annotations or presets: