Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Dokka 2.0.0 #4257

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions buildSrc/src/main/kotlin/Dokka.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import org.gradle.api.*
import org.gradle.api.publish.PublishingExtension
import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.*
import org.jetbrains.dokka.gradle.DokkaExtension
import java.io.*
import java.net.*

/**
* Package-list by external URL for documentation generation.
*/
fun Project.externalDocumentationLink(
fun Project.configureExternalLinks(
url: String,
packageList: File = projectDir.resolve("package.list")
) {
tasks.withType<AbstractDokkaLeafTask>().configureEach {
extensions.configure<DokkaExtension> {
dokkaSourceSets.configureEach {
externalDocumentationLink {
this.url = URL(url)
packageListUrl = packageList.toPath().toUri().toURL()
externalDocumentationLinks.register("api") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: because the name ("api") is fixed here, it's not possible to call Project::configureExternalLinks multiple times in one project (there will be an error during register call)

And at this point, it's called only once in every project, but it could change in future, so probably it could be better to provide this name explicitly in every project (as a parameter to a function, or may be just use value of url instead of name) - so that if multiple links will be added in future, there will be no obscure errors

this.url = URI.create(url)
this.packageListUrl = packageList.toURI()
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions buildSrc/src/main/kotlin/UnpackAar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import java.util.zip.ZipFile
val artifactType = Attribute.of("artifactType", String::class.java)
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)

fun Project.configureAar() = configurations.configureEach {
afterEvaluate {
if (isCanBeResolved && !isCanBeConsumed) {
fun Project.configureAar() =
configurations
.matching { it.isCanBeResolved && !it.isCanBeConsumed }
.configureEach {
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
}
}
}

fun DependencyHandlerScope.configureAarUnpacking() {
attributesSchema {
Expand Down
74 changes: 34 additions & 40 deletions buildSrc/src/main/kotlin/dokka-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import org.gradle.api.Project
import org.jetbrains.dokka.gradle.*
import java.io.File
import java.net.*


Expand All @@ -18,64 +20,58 @@ configure(subprojects.filterNot { projetsWithoutDokka.contains(it.name) }) {
configureExternalLinks()
}

// Setup top-level 'dokkaHtmlMultiModule' with templates
tasks.withType<DokkaMultiModuleTask>().named("dokkaHtmlMultiModule") {
setupDokkaTemplatesDir(this)
// For top-level multimodule collection
dokka {
setupDokkaTemplatesDir()
}

dependencies {
// Add explicit dependency between Dokka and Knit plugin
add("dokkaHtmlMultiModulePlugin", "org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
dokkaPlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")

subprojects.forEach {
if (it.name !in projetsWithoutDokka) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo.

Suggested change
if (it.name !in projetsWithoutDokka) {
if (it.name !in projectsWithoutDokka) {

(I made a suggestion to make it easier to see the typo, but maybe other places in the code should be updated.)

dokka(it)
}
}
}

// Dependencies for Knit processing: Knit plugin to work with Dokka
private fun Project.configurePathsaver() {
tasks.withType(DokkaTaskPartial::class).configureEach {
dependencies {
plugins("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
}
dependencies {
dokkaPlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
}
}

// Configure Dokka setup
private fun Project.condigureDokkaSetup() {
tasks.withType(DokkaTaskPartial::class).configureEach {
suppressInheritedMembers = true
setupDokkaTemplatesDir(this)
dokka {
dokkaPublications.configureEach {
suppressInheritedMembers = true
}

setupDokkaTemplatesDir()

dokkaSourceSets.configureEach {
jdkVersion = 11
includes.from("README.md")
noStdlibLink = true

externalDocumentationLink {
url = URL("https://kotlinlang.org/api/latest/jvm/stdlib/")
packageListUrl = rootProject.projectDir.toPath().resolve("site/stdlib.package.list").toUri().toURL()
}

// Something suspicious to figure out, probably legacy of earlier days
if (!project.isMultiplatform) {
dependsOn(project.configurations["compileClasspath"])
}
}

// Source links
dokkaSourceSets.configureEach {
sourceLink {
localDirectory = rootDir
remoteUrl = URL("https://github.com/kotlin/kotlinx.coroutines/tree/master")
remoteLineSuffix ="#L"
remoteUrl = URI("https://github.com/kotlin/kotlinx.coroutines/tree/master")
}
}

// TODO: WA for KT-71784
dokkaSourceSets.matching { it.name == "commonMain" }.configureEach {
suppress.set(true)
}
Comment on lines +61 to +65
Copy link
Contributor

@whyoleg whyoleg Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workaround could be removed after update to Dokka 2.0.0.

}
}

private fun Project.configureExternalLinks() {
tasks.withType<DokkaTaskPartial>() {
dokka {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: what is the reason why this manual linking to core artifact exists here at all?

dokkaSourceSets.configureEach {
externalDocumentationLink {
url = URL(coreModuleDocsUrl)
packageListUrl = File(coreModuleDocsPackageList).toURI().toURL()
externalDocumentationLinks.register("kotlinx-coroutines-core") {
url = URI(coreModuleDocsUrl)
packageListUrl = File(coreModuleDocsPackageList).toURI()
}
}
}
Expand All @@ -90,10 +86,8 @@ private fun Project.configureExternalLinks() {
* - Template setup: https://github.com/JetBrains/kotlin-web-site/blob/master/.teamcity/builds/apiReferences/kotlinx/coroutines/KotlinxCoroutinesPrepareDokkaTemplates.kt
* - Templates repository: https://github.com/JetBrains/kotlin-web-site/tree/master/dokka-templates
*/
private fun Project.setupDokkaTemplatesDir(dokkaTask: AbstractDokkaTask) {
dokkaTask.pluginsMapConfiguration = mapOf(
"org.jetbrains.dokka.base.DokkaBase" to """{ "templatesDir" : "${
project.rootProject.projectDir.toString().replace('\\', '/')
}/dokka-templates" }"""
)
private fun DokkaExtension.setupDokkaTemplatesDir() {
pluginsConfiguration.html {
templatesDir = file(rootDir.toString().replace('\\', '/') + "/dokka-templates")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootDir.resolve("dokka-templates")

}
}
11 changes: 3 additions & 8 deletions buildSrc/src/main/kotlin/knit-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ plugins {
id("kotlinx-knit")
}

// TODO check that roots are correct
knit {
siteRoot = "https://kotlinlang.org/api/kotlinx.coroutines"
moduleRoots = listOf(".", "integration", "reactive", "ui")
moduleDocs = "build/dokka/htmlPartial"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
moduleDocs = "build/dokka/htmlPartial"
moduleDocs = "build/dokka-module/html/module"

dokkaMultiModuleRoot = "build/dokka/htmlMultiModule/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dokkaMultiModuleRoot = "build/dokka/htmlMultiModule/"
dokkaMultiModuleRoot = "build/dokka/html/"

}

tasks.named("knitPrepare").configure {
val knitTask = this
// In order for knit to operate, it should depend on and collect
// all Dokka outputs from each module
allprojects {
val dokkaTasks = tasks.matching { it.name == "dokkaHtmlMultiModule" }
knitTask.dependsOn(dokkaTasks)
}
tasks.named("knitPrepare") {
dependsOn("dokka")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the coroutines Gradle config have a task named dokka? Or should this be dokkaGenerate?

}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ junit_version=4.12
junit5_version=5.7.0
knit_version=0.5.0
lincheck_version=2.18.1
dokka_version=1.9.20
dokka_version=2.0.0-Beta
org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled

helpers are not needed after migration


byte_buddy_version=1.10.9
reactor_version=3.4.1
reactor_docs_version=3.4.5
Expand Down
2 changes: 1 addition & 1 deletion integration/kotlinx-coroutines-guava/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ java {
sourceCompatibility = JavaVersion.VERSION_1_8
}

externalDocumentationLink(
configureExternalLinks(
url = "https://google.github.io/guava/releases/$guavaVersion/api/docs/"
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ dependencies {
testImplementation("androidx.test:monitor:1.2.0")
}

externalDocumentationLink(
configureExternalLinks(
url = "https://developers.google.com/android/reference/"
)
2 changes: 1 addition & 1 deletion integration/kotlinx-coroutines-slf4j/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-core:1.2.7")
}

externalDocumentationLink(
configureExternalLinks(
url = "https://www.slf4j.org/apidocs/"
)
3 changes: 2 additions & 1 deletion kotlinx-coroutines-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.gradle.api.tasks.testing.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.tasks.DokkaBaseTask
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
Expand Down Expand Up @@ -303,6 +304,6 @@ artifacts {
}

// Workaround for https://github.com/Kotlin/dokka/issues/1833: make implicit dependency explicit
tasks.named("dokkaHtmlPartial") {
tasks.withType<DokkaBaseTask>() {
dependsOn(jvmJar)
}
Comment on lines 306 to 309
Copy link
Member

@adam-enko adam-enko Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you try removing this workaround? It shouldn't be necessary in DGPv2.

If ./gradlew :dokkaGenerate still complains, then please raise an issue.

2 changes: 1 addition & 1 deletion reactive/kotlinx-coroutines-jdk9/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ tasks {
}
}

externalDocumentationLink(
configureExternalLinks(
url = "https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html"
)
2 changes: 1 addition & 1 deletion reactive/kotlinx-coroutines-reactive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tasks.check {
dependsOn(testNG)
}

externalDocumentationLink(
configureExternalLinks(
url = "https://www.reactive-streams.org/reactive-streams-$reactiveStreamsVersion-javadoc/"
)

Expand Down
2 changes: 1 addition & 1 deletion reactive/kotlinx-coroutines-reactor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tasks {

// the version of the docs can be different from the version of the Reactor
// library itself: https://github.com/reactor/reactor-core/issues/3794
externalDocumentationLink(
configureExternalLinks(
url = "https://projectreactor.io/docs/core/${version("reactor_docs")}/api/"
)

Expand Down
2 changes: 1 addition & 1 deletion ui/kotlinx-coroutines-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tasks.test {
}
}

externalDocumentationLink(
configureExternalLinks(
url = "https://developer.android.com/reference/"
)
/*
Expand Down