autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Synthetic bridge methods should be considered in ABI analysis.

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

Description

**Plugin version**
1.31.0

**Gradle version**
8.7

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

**(Optional) `reason` output for bugs relating to incorrect advice**
```
Source: main
------------
* Exposes 1 class: some.externa.dependency.ExternalEnum (implies api).
```

**Describe the bug**
When declaring file-level `private val` variables which are typed with some type from some dependency, that dependency is required to be an `api()` dependency, even though that file-level variable is only used in non-public contexts, such as a constructor argument to an `internal class`
```
private val FOO_ENUMS = ExternalEnum.entries.filter { it.name.startsWith("Foo") }

internal class MyClass(private val foos: Set = FOO_ENUMS)
```

**To Reproduce**
Steps to reproduce the behavior:
In on project, declare some type
```
enum class ExternalEnum {
FOO_ONE
FOO_TWO
BAR
}
```
In a second project, declare a class and a file-level `private val` variable
```
private val FOO_ENUMS = ExternalEnum.entries.filter { it.name.startsWith("Foo") }

internal class MyClass(private val foos: Set = FOO_ENUMS)
```

Now run
`./gradlew :second-project:reason --id :first-project`

**Expected behavior**
The output of `:reason` should be that `ExternalEnum` is a used class, implying `implementation`

**Additional context**
An existing work around is to move the file-level `private val` variables to the companion object of the class, eg
```
internal class MyClass(private val foos: Set = FOO_ENUMS) {
companion object {
private val FOO_ENUMS = ExternalEnum.entries.filter { it.name.startsWith("Foo") }
}
}
```
This class will result in the command giving the expected output.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the report with ./gradlew :second-project:reason --id :first-project, using the file-level private value and internal class shown in the issue. Trace the ABI analysis that treats the dependency type as exposed and account for synthetic bridge methods; done means :reason reports ExternalEnum as a used class implying implementation, matching the companion-object workaround.

Written by the indexing model from the issue text.

Assessment

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