Skip to content

Commit

Permalink
update: improve documentation on no-arg-plugin.md (#3754)
Browse files Browse the repository at this point in the history
* improve documentation on no-arg-plugin.md

- Provide a sample annotation to illustrate how the plugin should be used.
- Explain how to utilize the plugin using Kotlin DSL in Gradle, as an alternative for Groovy.

* update: update no-arg-plugin.md

updated wording
applied code style

---------

Co-authored-by: Andrey Polyakov <[email protected]>
  • Loading branch information
2 people authored and danil-pavlov committed Oct 17, 2023
1 parent bcb0dc3 commit 11a385d
Showing 1 changed file with 43 additions and 3 deletions.
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

0 comments on commit 11a385d

Please sign in to comment.