Skip to content

Incorrect advice to change configuration when @OptIn annotation is used #1595

@zepurplez

Description

@zepurplez

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions