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

Incorrect implementation vs api advice when interface implementor overrides return type

Open Egorand opened this issue 5 months ago • 2 comments

Build scan link

Reproduced in an internal project (cash-android), can share a build scan via internal channels.

Plugin version

2.19.0

Gradle version

8.14.3

JDK version

17

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

2.2.0

(Optional) Android Gradle Plugin (AGP) version

8.11.1

(Optional) reason output for bugs relating to incorrect advice

Toggle
------------------------------------------------------------
You asked about the dependency ':treehouse-android:viewmodels'.
You have been advised to change this dependency to 'implementation' from 'api'.
------------------------------------------------------------

Shortest path from :treehouse-android:presenters to :treehouse-android:viewmodels for debugCompileClasspath:
:treehouse-android:presenters
\--- :treehouse-android:viewmodels

Shortest path from :treehouse-android:presenters to :treehouse-android:viewmodels for debugRuntimeClasspath:
:treehouse-android:presenters
\--- :treehouse-android:viewmodels

Shortest path from :treehouse-android:presenters to :treehouse-android:viewmodels for debugUnitTestCompileClasspath:
:treehouse-android:presenters
\--- :treehouse-android:viewmodels

Shortest path from :treehouse-android:presenters to :treehouse-android:viewmodels for debugUnitTestRuntimeClasspath:
:treehouse-android:presenters
\--- :treehouse-android:viewmodels

Shortest path from :treehouse-android:presenters to :treehouse-android:viewmodels for debugAndroidTestCompileClasspath:
:treehouse-android:presenters
\--- :treehouse-android:viewmodels

Shortest path from :treehouse-android:presenters to :treehouse-android:viewmodels for debugAndroidTestRuntimeClasspath:
:treehouse-android:presenters
\--- :treehouse-android:viewmodels

Source: debug, android_test
---------------------------
(no usages)

Source: debug, main
-------------------
* Uses 1 class: com.squareup.cash.treehouse.android.viewmodels.TreehouseUiModel (implies implementation).

Source: debug, test
-------------------
(no usages)

Describe the bug

In the case when an interface implementor overrides the return type of an overridden method, DAGP suggests that the dependency that supplies that return type should be implementation, which seems incorrect.

To Reproduce Steps to reproduce the behavior:

  1. Interface is defined in a "common" module as follows.
fun interface PresenterFactory {
  fun create(screen: Screen, navigator: Navigator): Presenter<*, *>?
}
  1. The interface is implemented in the "presenters" module as follows. Note that TreehouseUiModel is declared in the "viewmodels" module.
class TreehousePresenterFactory @Inject internal constructor() : PresenterFactory {
  override fun create(
    screen: Screen,
    navigator: Navigator,
  ): Presenter<TreehouseUiModel, Nothing>? = TODO()
}
  1. When "presenters" depends on "viewmodels" as api (since TreehouseUiModel appears in the ABI of "presenters"), DAGP emits the following advice:
Advice for :treehouse-android:presenters
Existing dependencies which should be modified to be as indicated:
  implementation projects.treehouseAndroid.viewmodels (was api)

Expected behavior

DAGP should not emit the advice, since api is correct in this case.

Additional context

N/A

Egorand avatar Aug 12 '25 11:08 Egorand

Thanks for the report. A minimal reproducer would be ideal, since to fix this (if indeed it turns out to be a bug), I would need a regression test, which is itself essentially a minimal reproducer.

autonomousapps avatar Aug 13 '25 20:08 autonomousapps

Will do!

Egorand avatar Aug 21 '25 10:08 Egorand