ModuleVersionResolveException - libraries considered as undeclared
Closed this issue · 2 comments
plugin version: 0.51.0
Project: Android
The plugin configuration:
internal class DependencyAnalysisPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
VersionsPlugin().apply(project)
tasks.withType<DependencyUpdatesTask> {
checkForGradleUpdate = true
outputFormatter = "json"
outputDir = "build/dependencyUpdates"
reportfileName = "report"
doFirst {
// Removes repositories with non-stable versions to speed up task execution
project.repositories.removeAll {
it is MavenArtifactRepository && EXCLUDE_ARTIFACTS_LIST.any { keyword ->
it.url.toString().contains(keyword, ignoreCase = true)
}
}
}
//do not accept non-stable versions
rejectVersionIf {
!isStable(candidate.version)
}
}
}
companion object {
private val EXCLUDE_ARTIFACTS_LIST = listOf("snapshot", "beta", "alpha")
}
}
fun isStable(version: String): Boolean {
val stableKeywords = listOf("RELEASE", "FINAL", "GA")
val isStableKeywordPresent = stableKeywords.any { version.uppercase().contains(it) }
val stableVersionPattern = "^[0-9,.v-]+(-r)?$".toRegex()
val isStableVersionFormat = stableVersionPattern.matches(version)
return isStableKeywordPresent || isStableVersionFormat
}
Issue: I have several libraries considered as "undeclared" in the report with the following reason:
{
"group": "androidx.constraintlayout",
"name": "constraintlayout",
"version": "2.1.4",
"projectUrl": "2.1.4",
"userReason": null,
"reason": "org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve androidx.constraintlayout:constraintlayout:+.\nRequired by:\n project :Monolith\nCaused by: org.gradle.internal.component.NoMatchingGraphVariantsException: No matching variant of androidx.constraintlayout:constraintlayout:2.1.4 was found. The consumer was configured to find sources for use during runtime, compatible with any Java version, packaged as a jar, preferably optimized for Android, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:\n - Variant 'releaseApiPublication' declares a component, and its dependencies declared externally:\n - Incompatible because this component declares a library for use during compile-time, with the library elements 'aar' and the consumer needed documentation for use during runtime, packaged as a jar\n - Other compatible attributes:\n - Doesn't say anything about its target Java environment (preferred optimized for Android)\n - Doesn't say anything about its target Java version (required compatibility with any Java version)\n - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')\n - Doesn't say anything about the documentation type (required sources)\n - Variant 'releaseRuntimePublication' declares a component for use during runtime, and its dependencies declared externally:\n - Incompatible because this component declares a library, with the library elements 'aar' and the consumer needed documentation, packaged as a jar\n - Other compatible attributes:\n - Doesn't say anything about its target Java environment (preferred optimized for Android)\n - Doesn't say anything about its target Java version (required compatibility with any Java version)\n - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')\n - Doesn't say anything about the documentation type (required sources)\n\tat org.gradle.internal.component.resolution.failure.describer.IncompatibleGraphVariantsFailureDescriber.describeFailure(IncompatibleGraphVariantsFailureDescriber.java:42)\n\tat
....
It seems that the plugin actually manages to get the last version but in the projectUrl
field 🤔.
Can I do something about this?
Could it be because of Variant 'releaseRuntimePublication' declares a component for use during runtime, and its dependencies declared externally
?
I'm not very knowledgable when it comes to gradle's module metadata, variants, and android. I think to debug it one would need to look at their module. The failure looks similar to the #842 where @Vampire debugged that as "a bug in the Kotlin Gradle plugin 2.0.0, that these configurations that are known to be only partly resolvable are added at all." His recommended solution was "In this case either say "not my problem" and make JetBrains fix it, or exclude those bad configurations hard-coded as work-around.", so similar would apply to have Android fix their build or use our filterConfigurations to ignore the incorrect configuration.
org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve androidx.constraintlayout:constraintlayout:+.
Required by:
project :Monolith
Caused by: org.gradle.internal.component.NoMatchingGraphVariantsException: No matching variant of androidx.constraintlayout:constraintlayout:2.1.4 was found. The consumer was configured to find sources for use during runtime, compatible with any Java version, packaged as a jar, preferably optimized for Android, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- Variant 'releaseApiPublication' declares a component, and its dependencies declared externally:
- Incompatible because this component declares a library for use during compile-time, with the library elements 'aar' and the consumer needed documentation for use during runtime, packaged as a jar
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for Android)
- Doesn't say anything about its target Java version (required compatibility with any Java version)
- Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
- Doesn't say anything about the documentation type (required sources)
- Variant 'releaseRuntimePublication' declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares a library, with the library elements 'aar' and the consumer needed documentation, packaged as a jar
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for Android)
- Doesn't say anything about its target Java version (required compatibility with any Java version)
- Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
- Doesn't say anything about the documentation type (required sources)
at org.gradle.internal.component.resolution.failure.describer.IncompatibleGraphVariantsFailureDescriber.describeFailure(IncompatibleGraphVariantsFailureDescriber.java:42)
Thanks for your answer.
After looking at this issue, I've updated to Kotlin 2.0.20-Beta1
and I no longer have the issue ✅.