autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Incorrect advice to change configuration when @OptIn annotation is used

Open
#1,595 1 comment 0 reactions 0 assignees View on GitHub
bug toolchain:kotlin
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**Plugin version**
3.4.1

**Gradle version**
8.13.0

**JDK version**
17

**(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version**
2.1.21

**(Optional) `reason` output for bugs relating to incorrect advice**
```
You asked about the dependency ':lib3'.
You have been advised to change this dependency to 'implementation' from 'api'.
------------------------------------------------------------

Shortest path from :lib2 to :lib3 for compileClasspath:
:lib2
\--- :lib3

Shortest path from :lib2 to :lib3 for runtimeClasspath:
:lib2
\--- :lib3

Shortest path from :lib2 to :lib3 for testCompileClasspath:
:lib2
\--- :lib3

Shortest path from :lib2 to :lib3 for testRuntimeClasspath:
:lib2
\--- :lib3

Source: main
------------
* Imports 1 class: com.example.lib3.MyOptIn (implies implementation).

Source: test
------------
(no usages)
```

**Describe the bug**
```
Existing dependencies which should be modified to be as indicated:
implementation(project(":lib3")) (was api)
```

The plugin suggests changing configuration from _api_ to _implementation_ for the module containing OptIn annotation. As a result, the compiler fails to recognize invocations of methods annotated with OptIn.

before
Image

after
Image

**To Reproduce**
Execute
```
./gradlew :lib2:projectHealth
```

[OptInReproducer.zip](https://github.com/user-attachments/files/23416049/OptInReproducer.zip)

**Expected behavior**
Declare dependency with OptIn annotations as api or compileApi?

Contributor guide

Open the contributing guide

Research direction

Unpack OptInReproducer.zip and run ./gradlew :lib2:projectHealth to reproduce the advice changing :lib3 from api to implementation. Trace how the plugin handles com.example.lib3.MyOptIn and verify the recommendation against compiler recognition of methods annotated with @OptIn; done means the incorrect configuration advice is no longer emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.