aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src/main
diff options
context:
space:
mode:
authorOleg Yukhnevich <whyoleg@gmail.com>2023-08-08 16:55:59 +0300
committerGitHub <noreply@github.com>2023-08-08 15:55:59 +0200
commit80549e1f061d1eb22b12fc9a068536655ae299f7 (patch)
treeb120e0926d39457f1884286bf89f90f09940de16 /runners/gradle-plugin/src/main
parent0c21de181cdc896f63c5d534854df4d1cbf28c3a (diff)
downloaddokka-80549e1f061d1eb22b12fc9a068536655ae299f7.tar.gz
dokka-80549e1f061d1eb22b12fc9a068536655ae299f7.tar.bz2
dokka-80549e1f061d1eb22b12fc9a068536655ae299f7.zip
Add a workaround for native dependency metadata resolution (#3081)
Addresses #3068
Diffstat (limited to 'runners/gradle-plugin/src/main')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt48
1 files changed, 38 insertions, 10 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt
index 1d1d18fc..83cb87d6 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinClasspathUtils.kt
@@ -6,34 +6,49 @@ import org.jetbrains.dokka.gradle.isAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompileTool
internal fun Project.classpathOf(sourceSet: KotlinSourceSet): FileCollection {
val compilations = compilationsOf(sourceSet)
return if (compilations.isNotEmpty()) {
compilations
.map { compilation -> compilation.compileClasspathOf(project = this) }
- .reduce { acc, fileCollection -> acc + fileCollection }
+ .reduce(FileCollection::plus)
} else {
// Dokka suppresses source sets that do no have compilations
// since such configuration is invalid, it reports a warning or an error
sourceSet.withAllDependentSourceSets()
- .toList()
.map { it.kotlin.sourceDirectories }
- .reduce { acc, fileCollection -> acc + fileCollection }
+ .reduce(FileCollection::plus)
}
}
private fun KotlinCompilation.compileClasspathOf(project: Project): FileCollection {
+ val kgpVersion = project.getKgpVersion()
+
+ // if KGP version < 1.9 or org.jetbrains.dokka.classpath.useOldResolution=true
+ // we will use old (pre 1.9) resolution of classpath
+ if (kgpVersion == null ||
+ kgpVersion < KotlinGradlePluginVersion(1, 9, 0) ||
+ project.classpathProperty("useOldResolution", default = false)
+ ) {
+ return oldCompileClasspathOf(project)
+ }
+
+ return newCompileClasspathOf(project)
+}
+
+private fun KotlinCompilation.newCompileClasspathOf(project: Project): FileCollection {
+ val compilationClasspath = (compileTaskProvider.get() as? KotlinCompileTool)?.libraries ?: project.files()
+ return compilationClasspath + platformDependencyFiles(project)
+}
+
+private fun KotlinCompilation.oldCompileClasspathOf(project: Project): FileCollection {
if (this.target.isAndroidTarget()) { // Workaround for https://youtrack.jetbrains.com/issue/KT-33893
return this.classpathOf(project)
}
- val platformDependencyFiles: FileCollection = (this as? AbstractKotlinNativeCompilation)
- ?.target?.project?.configurations
- ?.findByName(@Suppress("DEPRECATION") this.defaultSourceSet.implementationMetadataConfigurationName) // KT-58640
- ?: project.files()
-
- return this.compileDependencyFiles + platformDependencyFiles + this.classpathOf(project)
+ return this.compileDependencyFiles + platformDependencyFiles(project) + this.classpathOf(project)
}
private fun KotlinCompilation.classpathOf(project: Project): FileCollection {
@@ -43,7 +58,7 @@ private fun KotlinCompilation.classpathOf(project: Project): FileCollection {
val shouldKeepBackwardsCompatibility = (kgpVersion != null && kgpVersion < KotlinGradlePluginVersion(1, 7, 0))
return if (shouldKeepBackwardsCompatibility) {
// removed since 1.9.0, left for compatibility with < Kotlin 1.7
- val classpathGetter= kotlinCompile::class.members
+ val classpathGetter = kotlinCompile::class.members
.first { it.name == "getClasspath" }
classpathGetter.call(kotlinCompile) as FileCollection
} else {
@@ -60,3 +75,16 @@ private fun KotlinCompilation.getKotlinCompileTask(kgpVersion: KotlinGradlePlugi
this.compileTaskProvider.get() as? KotlinCompile // introduced in 1.8.0
}
}
+
+private fun KotlinCompilation.platformDependencyFiles(project: Project): FileCollection {
+ val excludePlatformDependencyFiles = project.classpathProperty("excludePlatformDependencyFiles", default = false)
+
+ if (excludePlatformDependencyFiles) return project.files()
+ return (this as? AbstractKotlinNativeCompilation)
+ ?.target?.project?.configurations
+ ?.findByName(@Suppress("DEPRECATION") this.defaultSourceSet.implementationMetadataConfigurationName) // KT-58640
+ ?: project.files()
+}
+
+private fun Project.classpathProperty(name: String, default: Boolean): Boolean =
+ (findProperty("org.jetbrains.dokka.classpath.$name") as? String)?.toBoolean() ?: default