Skip to content

Migrate to DGPv2 #3005

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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
54 changes: 28 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ apiValidation {

knit {
siteRoot = "https://kotlinlang.org/api/kotlinx.serialization"
moduleDocs = "build/dokka/htmlMultiModule"
moduleDocs = "build/dokka-module/html/module"
dokkaMultiModuleRoot = "build/dokka/html/"
}

// Build API docs for all modules with dokka before running Knit
tasks.named("knitPrepare") {
dependsOn("dokka")
dependsOn("dokkaGenerate")
}


Expand Down Expand Up @@ -135,17 +136,14 @@ subprojects {
}
}

// Knit relies on Dokka task and it's pretty convenient
tasks.register("dokka") {
dependsOn("dokkaHtmlMultiModule")
}

tasks.withType<DokkaMultiModuleTask>().named("dokkaHtmlMultiModule") {
pluginsMapConfiguration.put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "${projectDir.toString().replace("\\", "/")}/dokka-templates" }""")
}

// apply conventions to root module and setup dependencies for aggregation
apply(plugin = "dokka-conventions")
dependencies {
dokkaPlugin(libs.dokka.pathsaver)
subprojects.forEach {
if (it.name in documentedSubprojects) {
dokka(it)
}
}
}

// == NPM setup ==
Expand All @@ -159,19 +157,23 @@ logger.warn("Project is using Kotlin Gradle plugin version: ${project.getKotlinP

// == projects lists and flags ==
// getters are required because of variable lazy initialization in Gradle
val unpublishedProjects get() = setOf(
"benchmark",
"guide",
"kotlinx-serialization-json-tests",
"proto-test-model",
)
val unpublishedProjects
get() = setOf(
"benchmark",
"guide",
"kotlinx-serialization-json-tests",
"proto-test-model",
)
val excludedFromBomProjects get() = unpublishedProjects + "kotlinx-serialization-bom"

val documentedSubprojects get() = setOf("kotlinx-serialization-core",
"kotlinx-serialization-json",
"kotlinx-serialization-json-okio",
"kotlinx-serialization-json-io",
"kotlinx-serialization-cbor",
"kotlinx-serialization-properties",
"kotlinx-serialization-hocon",
"kotlinx-serialization-protobuf")
val documentedSubprojects
get() = setOf(
"kotlinx-serialization-core",
"kotlinx-serialization-json",
"kotlinx-serialization-json-okio",
"kotlinx-serialization-json-io",
"kotlinx-serialization-cbor",
"kotlinx-serialization-properties",
"kotlinx-serialization-hocon",
"kotlinx-serialization-protobuf"
)
77 changes: 16 additions & 61 deletions buildSrc/src/main/kotlin/dokka-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.dokka.gradle.*
import java.net.URI

/*
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
Expand All @@ -18,62 +11,24 @@ dependencies {
dokkaPlugin(provider { extens.getByType<VersionCatalogsExtension>().named("libs").findLibrary("dokka.pathsaver").get().get() })
}

tasks.withType<DokkaTaskPartial>().named("dokkaHtmlPartial") {
outputDirectory.set(file("build/dokka"))


pluginsMapConfiguration.put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "${rootDir.resolve("dokka-templates").canonicalPath.replace('\\', '/')}" }""")

dokkaSourceSets {
configureEach {
includes.from(rootDir.resolve("dokka/moduledoc.md").path)

perPackageOption {
matchingRegex.set("kotlinx\\.serialization(\$|\\.).*")
reportUndocumented.set(true)
skipDeprecated.set(true)
}

// Internal API
perPackageOption {
matchingRegex.set("kotlinx\\.serialization.internal(\$|\\.).*")
suppress.set(true)
}

// Internal JSON API
perPackageOption {
matchingRegex.set("kotlinx\\.serialization.json.internal(\$|\\.).*")
suppress.set(true)
reportUndocumented.set(false)
}

// Workaround for typealias
perPackageOption {
matchingRegex.set("kotlinx\\.serialization.protobuf.internal(\$|\\.).*")
suppress.set(true)
reportUndocumented.set(false)
}

// Deprecated migrations
perPackageOption {
matchingRegex.set("kotlinx\\.protobuf(\$|\\.).*")
reportUndocumented.set(true)
skipDeprecated.set(true)
}
dokka {
pluginsConfiguration.html {
templatesDir = rootDir.resolve("dokka-templates")
}

// Deprecated migrations
perPackageOption {
matchingRegex.set("org\\.jetbrains\\.kotlinx\\.serialization\\.config(\$|\\.).*")
reportUndocumented.set(false)
skipDeprecated.set(true)
}
dokkaSourceSets.configureEach {
includes.from(rootDir.resolve("dokka/moduledoc.md").path)
reportUndocumented = true
skipDeprecated = true

sourceLink {
localDirectory.set(rootDir)
perPackageOption {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, there were multiple perPackageOption - most of them are obsolete or separate configurations for internal package. So, obsolete were removed and internal are handled by one regex now

Copy link
Member

Choose a reason for hiding this comment

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

Are @Deprecated declarations skipped now by default?

Copy link
Contributor Author

@whyoleg whyoleg Jun 16, 2025

Choose a reason for hiding this comment

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

Nope, only HIDDEN ones. Looks like I missed the flag during refactoring
Is it desirable behavior to skip deprecated with WARNING and ERROR declarations in all modules?

Copy link
Contributor Author

@whyoleg whyoleg Jun 25, 2025

Choose a reason for hiding this comment

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

I've brought back skipDeprecated = true

matchingRegex = ".*\\.internal(\\..*)?"
suppress = true
Copy link
Member

Choose a reason for hiding this comment

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

reportUndocumented = false ?

}

remoteUrl.set(URI("https://github.com/Kotlin/kotlinx.serialization/tree/master").toURL())
remoteLineSuffix.set("#L")
}
sourceLink {
localDirectory = rootDir
remoteUrl("https://github.com/Kotlin/kotlinx.serialization/tree/master")
}
}
}
}
11 changes: 4 additions & 7 deletions formats/json-io/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ kotlin {

project.configureJava9ModuleInfo()

tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
dokkaSourceSets {
configureEach {
externalDocumentationLink {
url.set(URI("https://kotlin.github.io/kotlinx-io/").toURL())
}
}
dokka.dokkaSourceSets.configureEach {
externalDocumentationLinks.register("kotlinx-io") {
url("https://kotlinlang.org/api/kotlinx-io/")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JIC: old URL is not accessible anymore

Copy link
Member

Choose a reason for hiding this comment

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

Local build gives me Failed to download package-list from https://kotlinlang.org/api/kotlinx-io/package-list, this might suggest that remote resource is not available, module is empty or dokka output got corrupted, and Source/Sink declarations in the doc are not linked, despite URL being available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, that looks strange, local build works fine on my side.
I can make it use the local package list (downloaded), as it was before for okio. The only case when the package list will become outdated is when a package is added or removed, so probably it should not be a big deal here to just use the local package list.
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added local package lists for both kotlinx-io and okio, so that the build will be less dependent on network failures.

JIC: Dokka by default still relies on downloading the package list of the stdlib.

packageListUrl = file("dokka/kotlinx-io.package-list").toURI()
}
}
10 changes: 10 additions & 0 deletions formats/json-io/dokka/kotlinx-io.package-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$dokka.format:html-v1
$dokka.linkExtension:html

module:kotlinx-io-bytestring
kotlinx.io.bytestring
module:kotlinx-io-core
kotlinx.io
kotlinx.io.files
module:kotlinx-io-okio
kotlinx.io.okio
14 changes: 4 additions & 10 deletions formats/json-okio/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,9 @@ kotlin {

project.configureJava9ModuleInfo()

tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
dokkaSourceSets {
configureEach {
externalDocumentationLink {
url.set(URI("https://square.github.io/okio/3.x/okio/").toURL())
packageListUrl.set(
file("dokka/okio.package.list").toURI().toURL()
)
}
}
dokka.dokkaSourceSets.configureEach {
externalDocumentationLinks.register("okio") {
url("https://square.github.io/okio/3.x/okio")
packageListUrl = file("dokka/okio.package-list").toURI()
}
}
Loading