Skip to content

Commit 7a87eab

Browse files
authored
Update Gradle dokka configuration to make sure "source" button is visible in all API docs (#3960)
1 parent 28ed2cd commit 7a87eab

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

gradle/dokka.gradle.kts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,31 @@ tasks.withType(DokkaTaskPartial::class).configureEach {
3737
}
3838
}
3939

40-
// Custom configuration for MPP modules
41-
tasks.withType(DokkaTaskPartial::class).configureEach {
42-
dokkaSourceSets.configureEach {
43-
sourceLink {
44-
val relPath = rootProject.projectDir.toPath().relativize(projectDir.toPath())
45-
localDirectory.set(projectDir.resolve("src"))
46-
remoteUrl.set(URL("https://github.com/kotlin/kotlinx.coroutines/tree/master/$relPath/src"))
47-
remoteLineSuffix.set("#L")
40+
fun GradleDokkaSourceSetBuilder.makeLinkMapping(projectDir: File) {
41+
sourceLink {
42+
val relPath = rootProject.projectDir.toPath().relativize(projectDir.toPath())
43+
localDirectory.set(projectDir.resolve("src"))
44+
remoteUrl.set(URL("https://github.com/kotlin/kotlinx.coroutines/tree/master/$relPath/src"))
45+
remoteLineSuffix.set("#L")
46+
}
47+
}
48+
49+
if (project.isMultiplatform) {
50+
// Configuration for MPP modules
51+
tasks.withType(DokkaTaskPartial::class).configureEach {
52+
// sources in MPP are located in moduleDir/PLATFORM/src,
53+
// where PLATFORM could be jvm, js, jdk8, concurrent, etc
54+
// configuration happens in buildSrc/src/main/kotlin/SourceSetsKt.configureMultiplatform
55+
dokkaSourceSets.matching { it.name.endsWith("Main") }.configureEach {
56+
val platform = name.dropLast(4)
57+
makeLinkMapping(project.file(platform))
58+
}
59+
}
60+
} else {
61+
// Configuration for JVM modules
62+
tasks.withType(DokkaTaskPartial::class).configureEach {
63+
dokkaSourceSets.named("main") {
64+
makeLinkMapping(projectDir)
4865
}
4966
}
5067
}

0 commit comments

Comments
 (0)