Incorrect implementation vs api advice when interface implementor overrides return type
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:
- Interface is defined in a "common" module as follows.
fun interface PresenterFactory {
fun create(screen: Screen, navigator: Navigator): Presenter<*, *>?
}
- The interface is implemented in the "presenters" module as follows. Note that
TreehouseUiModelis declared in the "viewmodels" module.
class TreehousePresenterFactory @Inject internal constructor() : PresenterFactory {
override fun create(
screen: Screen,
navigator: Navigator,
): Presenter<TreehouseUiModel, Nothing>? = TODO()
}
- When "presenters" depends on "viewmodels" as
api(sinceTreehouseUiModelappears 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
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.
Will do!