Skip to content

Commit afb8b31

Browse files
committed
Fix compatibility with changes in KGP
1 parent d0b0a28 commit afb8b31

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

dokka-runners/dokka-gradle-plugin/src/main/kotlin/adapters/KotlinAdapter.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,18 @@ private class KotlinCompilationDetailsBuilder(
453453
return when (this) {
454454
is KotlinMetadataCompilation<*> -> true
455455

456+
// Use string-based comparison, not the actual classes, because AGP has deprecated and
457+
// moved the Library/Application classes to a different package.
458+
// Using strings is more widely compatible.
456459
is KotlinJvmAndroidCompilation -> {
457-
// Use string-based comparison, not the actual classes, because AGP has deprecated and
458-
// moved the Library/Application classes to a different package.
459-
// Using strings is more widely compatible.
460-
val variantName = androidVariant::class.jvmName
460+
// `runCatching` is used here, in case `androidVariant` will be removed in a future version of KGP.
461+
val variantName = runCatching {
462+
// https://youtrack.jetbrains.com/issue/KT-77023:
463+
// `androidVariant` has `null` value in case of AGP/built-in Kotlin project.
464+
@Suppress("DEPRECATION", "UNNECESSARY_NOT_NULL_ASSERTION")
465+
androidVariant!!::class.jvmName
466+
}.getOrNull() ?: return true // published by default
467+
461468
"LibraryVariant" in variantName || "ApplicationVariant" in variantName
462469
}
463470

0 commit comments

Comments
 (0)