diff options
author | Anton Lakotko <antoha.by@gmail.com> | 2023-10-09 13:28:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-09 13:28:09 +0200 |
commit | 9809ae702cb9f9fad3c500df14a839e4a090180a (patch) | |
tree | 9afb337f994360c6f0201324ce6733216bf59a25 /runners/gradle-plugin/src | |
parent | 62d1143ed3f2f76c4f52eaaa1e079fc8b8c7f264 (diff) | |
download | dokka-9809ae702cb9f9fad3c500df14a839e4a090180a.tar.gz dokka-9809ae702cb9f9fad3c500df14a839e4a090180a.tar.bz2 dokka-9809ae702cb9f9fad3c500df14a839e4a090180a.zip |
Use compileDependencyFiles for getting compilation dependencies (#3147)
Co-authored-by: vmishenev <vad-mishenev@yandex.ru>
Diffstat (limited to 'runners/gradle-plugin/src')
2 files changed, 57 insertions, 3 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinNativeDistributionAccessor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinNativeDistributionAccessor.kt new file mode 100644 index 00000000..3180efef --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinNativeDistributionAccessor.kt @@ -0,0 +1,39 @@ +@file:Suppress("INVISIBLE_REFERENCE") +package org.jetbrains.dokka.gradle.kotlin + +import java.io.File +import org.gradle.api.Project +import org.jetbrains.kotlin.commonizer.KonanDistribution +import org.jetbrains.kotlin.commonizer.platformLibsDir +import org.jetbrains.kotlin.commonizer.stdlib +import org.jetbrains.kotlin.compilerRunner.konanHome +import org.jetbrains.kotlin.konan.target.KonanTarget + +/** + * Provides access to the Kotlin/Native distribution components: + * * [stdlibDir] -- stdlib directory + * * [platformDependencies] -- list of directories to platform dependencies + * + * It uses Kotlin Gradle Plugin API that is guaranteed to be present in: + * 1.5 <= kotlinVersion <= 1.9 + * + * It should not be used with Kotlin versions later than 1.9 + */ +internal class KotlinNativeDistributionAccessor( + project: Project +) { + private val konanDistribution = KonanDistribution( + @Suppress("INVISIBLE_MEMBER") + project.konanHome + ) + + val stdlibDir: File = konanDistribution.stdlib + + fun platformDependencies(target: KonanTarget): List<File> = konanDistribution + .platformLibsDir + .resolve(target.name) + .listLibraryFiles() + + private fun File.listLibraryFiles(): List<File> = listFiles().orEmpty() + .filter { it.isDirectory || it.extension == "klib" } +}
\ No newline at end of file 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 4fdc61c9..778261a7 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 @@ -10,7 +10,6 @@ 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) @@ -43,8 +42,24 @@ private fun KotlinCompilation.compileClasspathOf(project: Project): FileCollecti } private fun KotlinCompilation.newCompileClasspathOf(project: Project): FileCollection { - val compilationClasspath = (compileTaskProvider.get() as? KotlinCompileTool)?.libraries ?: project.files() - return compilationClasspath + platformDependencyFiles(project) + if (this.target.isAndroidTarget()) { // Workaround for https://youtrack.jetbrains.com/issue/KT-33893 + return this.classpathOf(project) + } + + val result = project.objects.fileCollection() + result.from({ compileDependencyFiles }) + + val kgpVersion = project.getKgpVersion() + // Since Kotlin 2.0 native distributiuon dependencies will be included to compileDependencyFiles + if (kgpVersion != null && kgpVersion <= KotlinGradlePluginVersion(1, 9, 255)) { + if (this is AbstractKotlinNativeCompilation) { + val kotlinNativeDistributionAccessor = KotlinNativeDistributionAccessor(project) + result.from(kotlinNativeDistributionAccessor.stdlibDir) + result.from(kotlinNativeDistributionAccessor.platformDependencies(konanTarget)) + } + } + + return result } private fun KotlinCompilation.oldCompileClasspathOf(project: Project): FileCollection { |