dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

Return type of suspend function not considered for public API

Open eygraber opened this issue 1 year ago • 3 comments

Plugin version 2.5.0

Gradle version 8.11.1

JDK version 22

Kotlin and Kotlin Gradle Plugin (KGP) version 2.0.21

Android Gradle Plugin (AGP) version 8.7.2

Describe the bug I have 3 modules:

module A

interface MyResult

module B (api(projects.A))

interface Foo {
  suspend fun bar(): MyResult
}

module C (implementation(projects.B), implementation(projects.A))

class Baz(
  private val foo: Foo,
) {
  suspend fun bing() {
    foo.bar()
  }
}

Running buildHealth fails with:

> Advice for :B
  Existing dependencies which should be modified to be as indicated:
    implementation(projects.A) (was api)
  
  Advice for :C
  Unused dependencies which should be removed:
    implementation(projects.A)

Running :B:reason --id :A:

------------------------------------------------------------
You asked about the dependency ':A'.
You have been advised to change this dependency to 'implementation' from 'api'.
------------------------------------------------------------

Source: devDebug, main
----------------------
* Imports 1 class: MyResult (implies implementation).

Running :B:reason --id :A:

------------------------------------------------------------
You asked about the dependency ':A'.
You have been advised to remove this dependency from 'implementation'.
------------------------------------------------------------

Source: devDebug, main
----------------------
(no usages)

If I follow the advice then compiling C fails:

e: Baz.kt:20:52 Cannot access class 'MyResult'. Check your module classpath for missing or conflicting dependencies.

eygraber avatar Nov 26 '24 23:11 eygraber

repro.zip

Running ./gradlew buildHealth on the repro above fails only when foo is a suspending function in services/foo/public/src/main/kotlin/template/services/foo/Foo.kt.

eygraber avatar Nov 27 '24 09:11 eygraber

Thanks for the report. I note the description of the issue (in the text) doesn't include any suspend functions. Does the repro contain suspend functions? (I haven't downloaded it yet.) If so, could you update the description?

autonomousapps avatar Dec 02 '24 23:12 autonomousapps

Updated. The repro project looks pretty different though, the description here was originally derived from that.

eygraber avatar Dec 02 '24 23:12 eygraber