autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Kotlin 2: bug when using associateWith: redeclaring dependencies on child configurations, leading to erroneous advice to remove or change dependencies that don't exist in build scripts

Open
#1,239 12 comments 0 reactions 0 assignees View on GitHub
blocked-by-jetbrains bug toolchain:kotlin
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**Build scan link**
https://scans.gradle.com/s/lozbs26qkgomy

**Plugin version**
1.33.0

**Gradle version**
8.9 and 8.10

**JDK version**
11.0.24

**(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version**
2.0.20-Beta2, 2.0.20-RC, and 2.0.20-RC2.

**(Optional) Android Gradle Plugin (AGP) version**
N/A

**(Optional) `reason` output for bugs relating to incorrect advice**
Numerous, but for example:

```txt
> Task :subprojects:time-logger:reason

----------------------------------------
You asked about the dependency 'org.springframework:spring-context:6.1.12 (libs.spring.context)'.
You have been advised to change this dependency to 'integrationTestImplementation' from 'integrationTestApi'.
----------------------------------------

Shortest path from :subprojects:time-logger to org.springframework:spring-context:6.1.12 (libs.spring.context) for integrationTestCompileClasspath:
:subprojects:time-logger
\--- org.springframework:spring-context:6.1.12

Shortest path from :subprojects:time-logger to org.springframework:spring-context:6.1.12 (libs.spring.context) for integrationTestRuntimeClasspath:
:subprojects:time-logger
\--- org.springframework:spring-context:6.1.12

Shortest path from :subprojects:time-logger to org.springframework:spring-context:6.1.12 (libs.spring.context) for compileClasspath:
:subprojects:time-logger
\--- org.springframework:spring-context:6.1.12

Shortest path from :subprojects:time-logger to org.springframework:spring-context:6.1.12 (libs.spring.context) for runtimeClasspath:
:subprojects:time-logger
\--- org.springframework:spring-context:6.1.12

Shortest path from :subprojects:time-logger to org.springframework:spring-context:6.1.12 (libs.spring.context) for testCompileClasspath:
:subprojects:time-logger
\--- org.springframework:spring-context:6.1.12

Shortest path from :subprojects:time-logger to org.springframework:spring-context:6.1.12 (libs.spring.context) for testRuntimeClasspath:
:subprojects:time-logger
\--- org.springframework:spring-context:6.1.12

Source: main
------------
* Exposes 1 class: org.springframework.context.annotation.Configuration (implies api).

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

Source: integrationTest
-----------------------
* Uses 2 classes: org.springframework.context.annotation.Configuration, org.springframework.context.annotation.Import (implies integrationTestImplementation).
```

**Describe the bug**
Per #1026, I've been using the following in the precompiled script plugins for my custom JVM Test Suite Plugin suites:

```kt
configure {
abi {
exclusions {
excludeSourceSets(testSuiteName) // E.g. "integrationTest"
}
}
}
```

With Kotlin 2.0.20-Beta1 and prior this works, and I don't get any advice to change `Api` dependencies to `Implementation`.

If I upgrade from 2.0.20-Beta1 to 2.0.20-Beta2, 2.0.20-RC, or 2.0.20-RC2, with no other changes, all that advice returns as if I wasn't filtering my test suite source sets from ABI analysis.

**To Reproduce**

1. Run `gradlew buildHealth`.

2.0.20-Beta2 reproducer:

https://github.com/sdkotlin/sd-kotlin-spring-talks/tree/f55c327ee46061982ceebdd745070cc78d5fa831

It does not reproduce with Kotlin 2.0.20-Beta1:

https://github.com/sdkotlin/sd-kotlin-spring-talks/tree/bcc1b9538b173a4b4be8ad7490808feb258d733f

It does not reproduce with a different but similarly-configured project when it's upgraded to Kotlin 2.0.20-Beta2:

https://github.com/sdkotlin/sd-kotlin-talks/tree/0b57a33323aa1d9209762d5a8ab4c652605e877a

**Expected behavior**
No `Api` to `Implementation` advice when ABI filtering the corresponding source sets.

**Additional context**
This seems to be at least a partial regression of #1026 with Kotlin 2.0.20-Beta2+.

Contributor guide

Open the contributing guide

Research direction

Start by running gradlew buildHealth in the linked 2.0.20-Beta2 reproducer and compare it with the 2.0.20-Beta1 revision. Inspect the DependencyAnalysisSubExtension ABI exclusions and the handling of custom JVM Test Suite child configurations or associateWith relationships. Done means the corresponding test-suite Api dependencies no longer receive erroneous Implementation advice when their source sets are excluded.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
build-system, tooling
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.