From 02fdeb2a67b6bb01c2f4afccaf578b89997f79b4 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 18 Sep 2019 11:58:30 +0200 Subject: Fix for Android classpath bug --- .../dokka/gradle/ConfigurationExtractor.kt | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'runners/gradle-plugin/src') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index 9f8dfc33..af952148 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult import java.io.File import java.io.Serializable @@ -56,13 +57,14 @@ class ConfigurationExtractor(private val project: Project) { } } - val commonTarget = targets.find { it.platformType == KotlinPlatformType.common } - val platformTargets = targets.filter { it.platformType != KotlinPlatformType.common } - val config = platformTargets.map { + val commonTargetPlatformData = targets.find { it.platformType == KotlinPlatformType.common }?.let { + PlatformData("common", getClasspath(it), getSourceSet(it), "common") + } + val config = targets.filter { it.platformType != KotlinPlatformType.common }.map { PlatformData(it.name, getClasspath(it), getSourceSet(it), it.platformType.toString()) } - return config + PlatformData("common", getClasspath(commonTarget), getSourceSet(commonTarget), "common") + return (config + commonTargetPlatformData).filterNotNull() } fun extractFromJavaPlugin(): PlatformData? = @@ -71,16 +73,16 @@ class ConfigurationExtractor(private val project: Project) { ?.let { PlatformData(null, emptyList(), it.toList(), "") } fun extractFromKotlinTasks(kotlinTasks: List): PlatformData? = - try { + try { kotlinTasks.map { extractFromKotlinTask(it) }.let { platformDataList -> PlatformData(null, platformDataList.flatMap { it.classpath }, platformDataList.flatMap { it.sourceRoots }, "") } } catch (e: Throwable) { - when (e){ - is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> - extractFromKotlinTasksTheHardWay(kotlinTasks) - else -> throw e - } + when (e){ + is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> + extractFromKotlinTasksTheHardWay(kotlinTasks) + else -> throw e + } } private fun extractFromKotlinTask(task: Task): PlatformData = @@ -137,9 +139,13 @@ class ConfigurationExtractor(private val project: Project) { return PlatformData(null, classpath, allSourceRoots.toList(), "") } - private fun getSourceSet(target: KotlinTarget?): List = getSourceSet(getMainCompilation(target)) + private fun getSourceSet(target: KotlinTarget): List = getSourceSet(getMainCompilation(target)) - private fun getClasspath(target: KotlinTarget?): List = getClasspath(getMainCompilation(target)) + private fun getClasspath(target: KotlinTarget): List = if (target.isAndroidTarget()) { + getClasspathFromAndroidTask(getMainCompilation(target)) + } else { + getClasspath(getMainCompilation(target)) + } private fun getSourceSet(compilation: KotlinCompilation<*>?): List = compilation ?.allKotlinSourceSets @@ -154,6 +160,11 @@ class ConfigurationExtractor(private val project: Project) { ?.filter { it.exists() } .orEmpty() + // This is a workaround for KT-33893 + private fun getClasspathFromAndroidTask(compilation: KotlinCompilation<*>?): List = (compilation + ?.compileKotlinTask as? KotlinCompile) + ?.classpath?.files?.toList() ?: getClasspath(compilation) + private fun getMainCompilation(target: KotlinTarget?): KotlinCompilation? = target?.compilations?.getByName(getMainCompilationName(target)) -- cgit