Skip to content

Commit

Permalink
Remove kotlin.Metadata annotation interaction doc as it does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
lupuuss committed Sep 12, 2024
1 parent 30eace6 commit 623e8ae
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions website/docs/Guides/Mocking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ track them. It's possible only for overridable methods.
Mocking final classes that are already compiled is currently not possible. This includes any class defined in the main
source set. However, you can "open" your final classes from main source set using [all-open plugin](https://kotlinlang.org/docs/all-open-plugin.html#gradle).

First, apply the `all-open` plugin:
Apply the `all-open` plugin:

```kotlin title="build.gradle.kts"
plugins {
Expand All @@ -179,12 +179,6 @@ plugins {
}
```

Second, choose one of two strategies:
* [Opening specific classes](#open-specific-classes)
* [Opening all classes](#open-all-classes)

#### Open specific classes

Define an annotation:

```kotlin
Expand Down Expand Up @@ -217,21 +211,6 @@ This should be fine for apps but can be problematic if your artifacts are consum
Refer to [this section](#avoid-opening-production-code) for further guidance.
:::

#### Open all classes

All Kotlin classes are annotated with `kotlin.Metadata` annotation, so you can use it with `all-open` plugin:

```kotlin title="build.gradle.kts"
allOpen {
annotation("kotlin.Metadata")
}
```
:::danger
All classes in your project are now open in production.
This should be fine for apps but can be problematic if your artifacts are consumed by other libraries.
Refer to [this section](#avoid-opening-production-code) for further guidance.
:::

#### Avoid opening production code

To avoid opening classes in production, you can conditionally apply the `allOpen` configuration based on whether a testing task is being executed:
Expand All @@ -246,11 +225,11 @@ val isTesting = gradle
.taskNames
.any(::isTestingTask)

if (isTesting) allOpen { /* selected config here */ }
if (isTesting) allOpen { /* ... */ }

```
:::danger
`gradle.startParameter.taskNames` only includes explicitly selected tasks.
If you run a task that depends on a test task but does not match `isTestingTask`, the `all-open` plugin will not be configured.
Adjust the task name condition based on your project type and the tasks you use.
:::
:::

0 comments on commit 623e8ae

Please sign in to comment.