From 782367d99ff212c902670717103f480fa3220f5c Mon Sep 17 00:00:00 2001 From: JulieGibbs Date: Wed, 3 May 2023 14:31:42 +0300 Subject: [PATCH] Workaround for Dokka bug #2590 Workaround for bug https://github.com/Kotlin/dokka/issues/2590 The way it's solved is by copying the individual java files to a separate folder which then is added as part of the Dokka sourceset --- sdk/build.gradle.kts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/sdk/build.gradle.kts b/sdk/build.gradle.kts index 9897f9af..a42e0f2b 100644 --- a/sdk/build.gradle.kts +++ b/sdk/build.gradle.kts @@ -147,11 +147,26 @@ android.productFlavors.all { if (upstreamApiDocFile.exists()) { // We include the files in "upstream-api-doc-list.txt" which might not have docs reportUndocumented.set(false) + + val tmpJavaForDokkaFolder = getAndCreateJavaForDokkaFolder() upstreamApiDocFile.forEachLine { if (!it.startsWith("//")) { - sourceRoots.from(file("../../$it")) + val file = file("../../$it") + if (!file.exists()) { + throw GradleException("Unable to add ${file.absolutePath}") + } else if (!file.isDirectory && file.extension == "java") { + // Due to bug https://github.com/Kotlin/dokka/issues/2590 in 1.5.31 we copy the + // individual Java files to a separate folder that will be included as sourceRoot + + // We use the full `it` to avoid collisions + file.copyTo(target = tmpJavaForDokkaFolder.resolve(it), overwrite = true) + } else { + sourceRoots.from(file) + } } } + // Always add the temporary folder to generate documentation + sourceRoot(tmpJavaForDokkaFolder) } } } @@ -167,3 +182,11 @@ project.apply { from("$rootDir/gradle/detekt.gradle") from("$rootDir/gradle/dependency-updates.gradle") } + +fun getAndCreateJavaForDokkaFolder() = + buildDir.resolve("dokka/tmp_java_files").also { + if (!it.exists() && !it.mkdirs()) { + throw GradleException("Couldn't create folder $it") + } + } +