autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Uses of `const val` not detected properly

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

Description

**Plugin version**
2.18.0

**Gradle version**
8.12.1

**JDK version**
17

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

**(Optional) `reason` output for bugs relating to incorrect advice**
```
------------------------------------------------------------
You asked about the dependency ':utils'.
You have been advised to remove this dependency from 'implementation'.
------------------------------------------------------------
```

**Describe the bug**
When module `:app` uses a `const val` from a named object in `:util`, and the two projects use the same java package, the usage of the constant from `:util` is not detected. This is very similar to #1430 but the fix for that looked for the `companion` object specifically, which is not in play here:

```kotlin
// :util
object Something {
const val EXAMPLE = "example"
}

// :app
fun main() {
println(Something.EXAMPLE)
}
```

**To Reproduce**
In [this reproducer](https://github.com/user-attachments/files/20662842/dagp-object-const-val.zip), run `buildHealth`

**Expected behavior**
No advice should be given

**Additional context**
Advice suggests removing `:util` dependency, which breaks compilation

Contributor guide

Open the contributing guide

Research direction

Run buildHealth with the linked dagp-object-const-val reproducer and confirm that the :app use of Something.EXAMPLE is missed. Read the handling related to #1430 and compare its companion-object assumption with named objects. Done means no removal advice is given for :util and the reproducer still compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.