Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore compatibility metadata variant if HMPP is enabled #2634

Merged
merged 1 commit into from Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,12 +6,25 @@ import org.jetbrains.dokka.gradle.isAndroidTarget
import org.jetbrains.dokka.utilities.cast
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val Project.isHMPPEnabled
// [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this
get() = (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false

internal fun Project.classpathOf(sourceSet: KotlinSourceSet): FileCollection {
val compilations = compilationsOf(sourceSet)
return if (compilations.isNotEmpty()) {
compilations
/**
* If the project has enabled Compatibility Metadata Variant (produces legacy variant),
* we don't touch it due to some dependant library
* might be published without Compatibility Metadata Variant.
* Dokka needs only HMPP variant
* Ignore [org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation] for `commonMain` sourceSet with name `main`
*/
.filterNot { compilation -> isHMPPEnabled && compilation is KotlinCommonCompilation && compilation.name == "main" }
.map { compilation -> compileClasspathOf(compilation) }
.reduce { acc, fileCollection -> acc + fileCollection }
} else {
Expand Down