You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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<ExternalEnum> = 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<ExternalEnum> = 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<ExternalEnum> = 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.
The text was updated successfully, but these errors were encountered:
Interestingly enough, this only happens with the exact setup you have. If your internal class instead looks like internal class MyClass(private val foos: List<ExternalEnum>)
then DAGP doesn't advise changing the dependency declaration. I think there's some kind of synthetic bridge class that is actually public in the bytecode. Investigating...
I created another repro in my project and decompiled it to Java. Here's what it looks like. You can clearly see the public methods that "expose" the private property.
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 adviceDescribe the bug
When declaring file-level
private val
variables which are typed with some type from some dependency, that dependency is required to be anapi()
dependency, even though that file-level variable is only used in non-public contexts, such as a constructor argument to aninternal class
To Reproduce
Steps to reproduce the behavior:
In on project, declare some type
In a second project, declare a class and a file-level
private val
variableNow run
./gradlew :second-project:reason --id :first-project
Expected behavior
The output of
:reason
should be thatExternalEnum
is a used class, implyingimplementation
Additional context
An existing work around is to move the file-level
private val
variables to the companion object of the class, egThis class will result in the command giving the expected output.
The text was updated successfully, but these errors were encountered: