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

Kotlin companion object constant reported as unused

Open ianbrandt opened this issue 10 months ago • 1 comments

Build scan link https://scans.gradle.com/s/3rlir55wk75cc

Plugin version 2.10.1

Gradle version 8.12.1, 8.13-rc-2

JDK version 17, 21

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

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

(Optional) reason output for bugs relating to incorrect advice

[1m------------------------------------------------------------
You asked about the dependency ':subprojects:constant-dependencies:constant-producer'.[0m
You have been advised to remove this dependency from '[31mimplementation[0m'.
[1m------------------------------------------------------------[0m

[1mShortest path from :subprojects:constant-dependencies:constant-consumer to :subprojects:constant-dependencies:constant-producer for compileClasspath:[0m
:subprojects:constant-dependencies:constant-consumer
\--- :subprojects:constant-dependencies:constant-producer

[1mShortest path from :subprojects:constant-dependencies:constant-consumer to :subprojects:constant-dependencies:constant-producer for runtimeClasspath:[0m
:subprojects:constant-dependencies:constant-consumer
\--- :subprojects:constant-dependencies:constant-producer

[1mShortest path from :subprojects:constant-dependencies:constant-consumer to :subprojects:constant-dependencies:constant-producer for testCompileClasspath:[0m
:subprojects:constant-dependencies:constant-consumer
\--- :subprojects:constant-dependencies:constant-producer

[1mShortest path from :subprojects:constant-dependencies:constant-consumer to :subprojects:constant-dependencies:constant-producer for testRuntimeClasspath:[0m
:subprojects:constant-dependencies:constant-consumer
\--- :subprojects:constant-dependencies:constant-producer

No compile-time usages detected for this runtime-only dependency.

Describe the bug The owning project of an imported companion object constant is being reported as unused.

To Reproduce Steps to reproduce the behavior:

  1. Import a companion object constant from a Kotlin source in one project to to the Kotlin source of another and use it, e.g.:

Producer Project

package constants.producer

class CompanionConstants {

	companion object {

		const val TESTING: String = "Testing"
	}
}

Consumer Project

package constants.consumer

import constants.producer.CompanionConstants.Companion.TESTING

fun main() {
	println(TESTING)
}

Expected behavior The producer project is not reported as unused.

Additional context #57, #66, #149, #408, #687

ianbrandt avatar Feb 24 '25 22:02 ianbrandt

Thanks for the report!

autonomousapps avatar Mar 06 '25 18:03 autonomousapps

This appears to be fixed in 2.18.0 (and apparently GitHub automatically closed it based on a corresponding commit comment I made in my separate reproducer project).

ianbrandt avatar Jun 10 '25 06:06 ianbrandt