Skip to content

Commit

Permalink
Update Gradle dokka configuration to make sure "source" button is vis…
Browse files Browse the repository at this point in the history
…ible in all API docs (#3960)
  • Loading branch information
whyoleg authored Nov 30, 2023
1 parent 28ed2cd commit 7a87eab
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions gradle/dokka.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,31 @@ tasks.withType(DokkaTaskPartial::class).configureEach {
}
}

// Custom configuration for MPP modules
tasks.withType(DokkaTaskPartial::class).configureEach {
dokkaSourceSets.configureEach {
sourceLink {
val relPath = rootProject.projectDir.toPath().relativize(projectDir.toPath())
localDirectory.set(projectDir.resolve("src"))
remoteUrl.set(URL("https://github.com/kotlin/kotlinx.coroutines/tree/master/$relPath/src"))
remoteLineSuffix.set("#L")
fun GradleDokkaSourceSetBuilder.makeLinkMapping(projectDir: File) {
sourceLink {
val relPath = rootProject.projectDir.toPath().relativize(projectDir.toPath())
localDirectory.set(projectDir.resolve("src"))
remoteUrl.set(URL("https://github.com/kotlin/kotlinx.coroutines/tree/master/$relPath/src"))
remoteLineSuffix.set("#L")
}
}

if (project.isMultiplatform) {
// Configuration for MPP modules
tasks.withType(DokkaTaskPartial::class).configureEach {
// sources in MPP are located in moduleDir/PLATFORM/src,
// where PLATFORM could be jvm, js, jdk8, concurrent, etc
// configuration happens in buildSrc/src/main/kotlin/SourceSetsKt.configureMultiplatform
dokkaSourceSets.matching { it.name.endsWith("Main") }.configureEach {
val platform = name.dropLast(4)
makeLinkMapping(project.file(platform))
}
}
} else {
// Configuration for JVM modules
tasks.withType(DokkaTaskPartial::class).configureEach {
dokkaSourceSets.named("main") {
makeLinkMapping(projectDir)
}
}
}

0 comments on commit 7a87eab

Please sign in to comment.