Skip to content

Commit f4c9405

Browse files
committed
Upgrade Dokka (make things build again)
1 parent 2dfa471 commit f4c9405

File tree

5 files changed

+111
-12
lines changed

5 files changed

+111
-12
lines changed

build.gradle.kts

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel
2222
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
23+
import org.jetbrains.dokka.gradle.DokkaTask
2324
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
2425
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
2526
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
@@ -105,5 +106,14 @@ idea {
105106
}
106107
}
107108

108-
tasks.withType<DokkaMultiModuleTask>().configureEach {
109+
dependencies {
110+
dokka(projects.core)
111+
dokka(projects.coreJdk)
112+
dokka(projects.coreAndroid)
113+
dokka(projects.serialization)
114+
dokka(projects.serialutil)
115+
}
116+
117+
tasks.dokkaHtml {
118+
val x: DokkaTask? = this
109119
}

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ xmlutil_versiondesc=
2626
kotlin.code.style=official
2727
native.deploy=
2828
xmlutil.wasmEnabled=false
29+
org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers
30+
#org.jetbrains.dokka.experimental.tryK2=true

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion = "1.8"
33
binaryValidator = "0.16.3"
44
dateTime = "0.6.1"
5-
dokka = "1.9.20"
5+
dokka = "2.0.0"
66
javaVersion = "8"
77
jmh = "0.7.2"
88
jmh-core = "1.37"

project-plugins/src/main/kotlin/net/devrieze/gradle/ext/dokka.kt

+96-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.gradle.api.provider.Provider
2525
import org.gradle.kotlin.dsl.assign
2626
import org.gradle.kotlin.dsl.withType
2727
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
28+
import org.jetbrains.dokka.gradle.DokkaExtension
29+
import org.jetbrains.dokka.gradle.DokkaTask
2830
import org.jetbrains.dokka.gradle.GradleDokkaSourceSetBuilder
31+
import org.jetbrains.dokka.gradle.engine.parameters.DokkaSourceSetSpec
32+
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier
33+
import org.jetbrains.dokka.gradle.tasks.DokkaGenerateModuleTask
34+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
2935
import java.net.URI
3036
import java.net.URL
3137

@@ -35,18 +41,27 @@ fun Project.configureDokka(
3541
dokkaOverrideTarget: Provider<String?>
3642
) {
3743
logger.lifecycle("Configuring dokka for project($name)")
44+
tasks.configureEach {
45+
if (name.contains("dokka", ignoreCase = true)) {
46+
logger.lifecycle("Dokka task: ${name} (${this.javaClass.simpleName})")
47+
}
48+
}
3849
tasks.withType<AbstractDokkaLeafTask>().configureEach {
39-
if (this is AbstractDokkaLeafTask) {
40-
logger.info("Configuring dokka task: ${this.name}")
41-
moduleName.convention(myModuleName)
42-
moduleVersion.convention(myModuleVersion)
50+
logger.lifecycle("Configuring dokka task: ${name} (${this.javaClass.simpleName})")
51+
moduleName.convention(myModuleName)
52+
moduleVersion.convention(myModuleVersion)
4353

44-
dokkaSourceSets.configureEach {
45-
this@configureDokka.configureDokkaSourceSet(this, dokkaOverrideTarget.getOrNull())
46-
}
54+
dokkaSourceSets.configureEach {
55+
this@configureDokka.configureDokkaSourceSet(this, dokkaOverrideTarget.getOrNull())
56+
}
57+
}
58+
extensions.configure<DokkaExtension>("dokka") {
59+
logger.lifecycle("Configuring dokka task: ${name} (${this.javaClass.simpleName})")
60+
moduleName.convention(myModuleName)
61+
moduleVersion.convention(myModuleVersion)
4762

48-
} else if ("dokka" in name.lowercase()) {
49-
logger.error("Non-configured dokka task: ${project.name}:${name} : ${this.javaClass.name}")
63+
dokkaSourceSets.configureEach {
64+
this@configureDokka.configureDokkaSourceSet(this, dokkaOverrideTarget.getOrNull())
5065
}
5166
}
5267
}
@@ -123,3 +138,75 @@ private fun Project.configureDokkaSourceSet(
123138
logger.warn("Sourceset ${project.name}:${sourceSet.name} suppressed")
124139
}
125140
}
141+
142+
private fun Project.configureDokkaSourceSet(
143+
sourceSet: DokkaSourceSetSpec,
144+
dokkaOverrideTarget: String?
145+
) {
146+
if (!sourceSet.suppress.get()) {
147+
logger.info("Configuring dokkaSourceSet:${project.name}:${sourceSet.name}")
148+
with(sourceSet) {
149+
if (name.startsWith("android")) {
150+
enableAndroidDocumentationLink = true
151+
enableJdkDocumentationLink = false
152+
} else {
153+
enableAndroidDocumentationLink = false
154+
enableJdkDocumentationLink = true
155+
}
156+
displayName.set(
157+
dokkaOverrideTarget ?: when (val dn = displayName.get()?.lowercase()) {
158+
"jdk" -> "JVM"
159+
"jvm",
160+
"javashared",
161+
"commonjvm",
162+
"jvmcommon" -> "JVM"
163+
"android" -> "Android"
164+
"common" -> "Common"
165+
"js" -> "JS"
166+
"native" -> "Native"
167+
"commondom" -> "Native"
168+
"wasmcommon" -> "Wasm"
169+
else -> dn
170+
}
171+
)
172+
logger.lifecycle("Configuring dokka on sourceSet: :${project.name}:$name = ${displayName.orNull}")
173+
174+
documentedVisibilities = setOf(VisibilityModifier.Public, VisibilityModifier.Protected)
175+
176+
skipEmptyPackages = true
177+
skipDeprecated = true
178+
179+
for (sourceRoot in sourceSet.sourceRoots) {
180+
val relativeRoot = sourceRoot.relativeTo(rootProject.projectDir)
181+
logger.lifecycle("Adding source link for root: $relativeRoot")
182+
sourceLink {
183+
localDirectory = sourceRoot
184+
val relURI = relativeRoot.toURI()
185+
val absUrl = URI.create("https://github.com/pdvrieze/xmlutil/tree/master/").resolve(relURI)
186+
remoteUrl = absUrl
187+
}
188+
}
189+
190+
externalDocumentationLinks.apply {
191+
url("https://kotlinlang.org/api/kotlinx.serialization/")
192+
}
193+
194+
perPackageOption {
195+
matchingRegex.set(".*\\.(impl|internal)(|\\..*)")
196+
suppress.set(true)
197+
}
198+
logger.lifecycle("Dokka source set: '$name'")
199+
if ("Main" in name) {
200+
val readme = project.file(project.relativePath("src/README.md"))
201+
if (readme.exists() && readme.canRead()) {
202+
includes.from(listOf(readme))
203+
logger.lifecycle("Adding $readme to sourceSet :${project.name}:${name}(${displayName.orNull})")
204+
} else {
205+
logger.warn("Missing $readme for project ${project.name}")
206+
}
207+
}
208+
}
209+
} else {
210+
logger.warn("Sourceset ${project.name}:${sourceSet.name} suppressed")
211+
}
212+
}

project-plugins/src/main/kotlin/net/devrieze/gradle/ext/publishing.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fun Project.doPublish(
4343

4444
val javadocJarTask = tasks.create<Jar>("javadocJar") {
4545
archiveClassifier.set("javadoc")
46-
from(tasks.named("dokkaHtml"))
46+
from(tasks.named("dokkaGenerateModuleHtml"))
4747
}
4848

4949
configure<PublishingExtension> {

0 commit comments

Comments
 (0)