Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve documentation on no-arg-plugin.md #3754

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions docs/topics/no-arg-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,46 @@

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.
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](#jpa-support)).

## In your Kotlin file

Add new annotations to mark the code that needs a zero-argument constructor:

```kotlin
package com.my

annotation class Annotation
```

## Gradle

Add the plugin using Gradle's plugins DSL:

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">

```kotlin
plugins {
kotlin("plugin.noarg") version "%kotlinVersion%"
}
```

</tab>
<tab title="Groovy" group-key="groovy">

```groovy
plugins {
id "org.jetbrains.kotlin.plugin.noarg" version "%kotlinVersion%"
id "org.jetbrains.kotlin.plugin.noarg" version "%kotlinVersion%"
}
```

</tab>
</tabs>

Then specify the list of no-arg annotations that must lead to generating a no-arg constructor for the annotated classes:

```groovy
Expand Down Expand Up @@ -74,12 +99,27 @@ and [`@MappedSuperclass`](https://docs.oracle.com/javaee/7/api/javax/persistence

Add the plugin using the Gradle plugins DSL:

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">

```kotlin
plugins {
kotlin("plugin.jpa") version "%kotlinVersion%"
}
```

</tab>
<tab title="Groovy" group-key="groovy">

```groovy
plugins {
id "org.jetbrains.kotlin.plugin.jpa" version "%kotlinVersion%"
id "org.jetbrains.kotlin.plugin.jpa" version "%kotlinVersion%"
}
```

</tab>
</tabs>

In Maven, enable the `jpa` plugin:

```xml
Expand Down
Loading