Skip to content

Commit

Permalink
Workaround for Dokka bug #2590
Browse files Browse the repository at this point in the history
Workaround for bug Kotlin/dokka#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
  • Loading branch information
JulieGibbs committed May 3, 2023
1 parent 2f304a8 commit 782367d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion sdk/build.gradle.kts
Expand Up @@ -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)
}
}
}
Expand All @@ -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")
}
}

0 comments on commit 782367d

Please sign in to comment.