dependency-analysis-gradle-plugin
dependency-analysis-gradle-plugin copied to clipboard
1.20 introduced wrong advice for kotlin-test
Plugin version
1.20.0
Gradle version
8.1.1
(Optional) Android Gradle Plugin (AGP) version
8.0.0
reason output for bugs relating to incorrect advice
----------------------------------------
You asked about the dependency 'org.jetbrains.kotlin:kotlin-test:1.8.20'.
You have been advised to remove this dependency from 'androidTestImplementation'.
----------------------------------------
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for debugCompileClasspath
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for debugRuntimeClasspath
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for debugUnitTestCompileClasspath
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for debugUnitTestRuntimeClasspath
Shortest path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for debugAndroidTestCompileClasspath:
:app
\--- org.jetbrains.kotlin:kotlin-test:1.8.20
Shortest path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for debugAndroidTestRuntimeClasspath:
:app
\--- org.jetbrains.kotlin:kotlin-test:1.8.20
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for releaseCompileClasspath
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for releaseRuntimeClasspath
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for releaseUnitTestCompileClasspath
There is no path from :app to org.jetbrains.kotlin:kotlin-test:1.8.20 for releaseUnitTestRuntimeClasspath
Source: debug, main
-------------------
(no usages)
Source: release, main
---------------------
(no usages)
Source: debug, test
-------------------
(no usages)
Source: release, test
---------------------
(no usages)
Source: debug, android_test
---------------------------
(no usages)
build-health-report.txt says:
Advice for :app
Unused dependencies which should be removed:
androidTestImplementation('org.jetbrains.kotlin:kotlin-test:1.8.20') { capabilities {
requireCapability('org.jetbrains.kotlin:kotlin-test-framework-junit')
}}
Describe the bug
1.19 didn't report any violations in my side-project. 1.20 started complaining about org.jetbrains.kotlin:kotlin-test I use in androidTestImplementation. When I delete the dependency then the test doesn't compile.
To Reproduce The project is public on github, so you can check out the full dependency setup, but it's pretty minimal. Here's the PR that bumps plugin to 1.20: https://github.com/marcin-kozinski/alusia/pull/64
Expected behavior
No violation reported or correct advice (removing from androidTestImplementation breaks the project, so sounds like incorrect advice).
Additional context
I am assuming this is because of the new capabilities functionality. Maybe JetBrains are doing something weird with Kotlin dependencies in general and kotlin-test specifically? I'm happy to configure an ignore if they are weird and it would be a nuisance to work around this in the plugin, but appreciate looking into it and some advice.
Thanks for the report. @jjohannes what do you think?
I'll have to investigate what's going on. org.jetbrains.kotlin:kotlin-test certainly has interesting metadata. It adds additional capabilities like org.jetbrains.kotlin:kotlin-test-framework-junit which is mentioned in the advice. This may not fit some of the assumptions we are currently making. Or maybe this reveals some issue that was just hidden before. I can take a look at this.
The plugin is doing the analysis correct. There are actually two variants (two Jars) – jvmApi and junitApiVariant. You can see it in a build scan here.
The Jar from the junitApiVariant is not needed. That's why the plugin is reporting on it.
The dependency to that second Jar is added by the Kotlin plugins. I haven't found a good opt-out for this. 😠
https://github.com/JetBrains/kotlin/blob/09f4f0af66a6259d3b42765b3bd8cd89b2567938/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kotlinTestDependencyManagement.kt#L136-L145
(rant) This annoys me. It's like a disease that plugins – and even Gradle core itself – automatically add dependencies even though you might not use them and there is not opt-out. It breaks the whole idea of dependency analysis. It might be nice for simple projects, but if you want to have clean classpaths through clear dependency declarations it is just super annoying. And it often takes for ever to find out whats going on. 😞
Maybe as an actionable item for this and similar issues: The exclusion DSL could be extended to also support the "Gradle variant identifier" so that the dependency here can be ignored. E.g.:
dependencyAnalysis.issues {
onUnusedDependencies {
exclude("org.jetbrains.kotlin:kotlin-test") {
capability("org.jetbrains.kotlin:kotlin-test-framework-junit")
}
}
}
Still an issue with 1.26.0?
Still a problem with the following configurations:
Plugin version
1.26.0/1.28.0
Gradle version
8.5
(Optional) Android Gradle Plugin (AGP) version
8.2.0
By the way I'm using the following workaround:
dependencyAnalysis {
dependencies {
bundle('kotlin-test') {
includeDependency('org.jetbrains.kotlin:kotlin-test')
}
}
}
Thanks for confirming it's still an issue 👍