Skip to content

Commit 3ec6de7

Browse files
authored
Merge pull request #234 from simple-robot/update-dokka
Update dokka to 2.0.0
2 parents 89d4aa9 + 71a4ee3 commit 3ec6de7

File tree

17 files changed

+179
-174
lines changed

17 files changed

+179
-174
lines changed

.github/workflows/publish-kdoc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
--warning-mode all
4646
-x test
4747
--build-cache
48-
dokkaHtmlMultiModule
48+
dokkaGenerate
4949
5050
- name: Push to doc repository
5151
uses: peaceiris/actions-gh-pages@v3

.github/workflows/publish-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
--warning-mode all
132132
-x test
133133
--build-cache
134-
dokkaHtmlMultiModule
134+
dokkaGenerate
135135
136136
- name: Push to doc repository
137137
uses: peaceiris/actions-gh-pages@v3

.github/workflows/publish-snapshot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
--warning-mode all
120120
-x test
121121
--build-cache
122-
dokkaHtmlMultiModule
122+
dokkaGenerate
123123
124124
- name: Push to doc repository
125125
uses: peaceiris/actions-gh-pages@v3

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ val kotlinVersion: String = libs.versions.kotlin.get()
3333
dependencies {
3434
implementation(kotlin("gradle-plugin", kotlinVersion))
3535
implementation(kotlin("serialization", kotlinVersion))
36-
implementation(libs.bundles.dokka)
36+
implementation(libs.dokka.plugin)
3737

3838
// see https://github.com/gradle-nexus/publish-plugin
3939
implementation("io.github.gradle-nexus:publish-plugin:2.0.0")
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import org.gradle.api.Project
2+
import org.gradle.api.tasks.compile.JavaCompile
3+
import org.jetbrains.dokka.gradle.DokkaExtension
4+
import org.jetbrains.dokka.gradle.engine.parameters.DokkaSourceSetSpec
5+
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier
6+
import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters
7+
import java.io.File
8+
import java.net.URI
9+
import java.time.Year
10+
11+
/*
12+
* Copyright (c) 2025. ForteScarlet.
13+
*
14+
* This file is part of simbot-component-onebot.
15+
*
16+
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
17+
* of the GNU Lesser General Public License as published by the Free Software Foundation,
18+
* either version 3 of the License, or (at your option) any later version.
19+
*
20+
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
21+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22+
* See the GNU Lesser General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
25+
* If not, see <https://www.gnu.org/licenses/>.
26+
*/
27+
28+
fun DokkaExtension.configSourceSets(project: Project) {
29+
dokkaSourceSets.configureEach {
30+
skipEmptyPackages.set(true)
31+
suppressGeneratedFiles.set(false)
32+
documentedVisibilities(
33+
VisibilityModifier.Public,
34+
VisibilityModifier.Protected
35+
)
36+
project.tasks.withType(JavaCompile::class.java).firstOrNull()
37+
?.targetCompatibility?.toInt().also {
38+
logger.info("project {} found jdkVersionValue: {}", project, it)
39+
}?.also {
40+
jdkVersion.set(it)
41+
}
42+
43+
configModuleMdInclude(project)
44+
45+
perPackageOption {
46+
matchingRegex.set(".*internal.*") // will match all .internal packages and sub-packages
47+
suppress.set(true)
48+
}
49+
50+
configSourceLink(project)
51+
52+
configExternalDocumentations()
53+
}
54+
}
55+
56+
fun DokkaSourceSetSpec.configModuleMdInclude(project: Project) {
57+
val moduleFile = project.file("Module.md")
58+
if (moduleFile.exists() && moduleFile.length() > 0) {
59+
includes.from("Module.md")
60+
}
61+
}
62+
63+
fun DokkaSourceSetSpec.configSourceLink(project: Project) {
64+
sourceLink {
65+
localDirectory.set(File(project.projectDir, "src"))
66+
val relativeTo = project.projectDir.relativeTo(project.rootProject.projectDir).toString()
67+
.replace('\\', '/')
68+
remoteUrl.set(URI.create("${P.HOMEPAGE}/tree/dev/main/$relativeTo/src"))
69+
remoteLineSuffix.set("#L")
70+
}
71+
}
72+
73+
fun DokkaSourceSetSpec.configExternalDocumentations() {
74+
fun externalDocumentation(name: String, docUrl: URI, suffix: String = "package-list") {
75+
externalDocumentationLinks.register(name) {
76+
url.set(docUrl)
77+
packageListUrl.set(docUrl.resolve(suffix))
78+
}
79+
}
80+
81+
// kotlin-coroutines doc
82+
externalDocumentation(
83+
"kotlinx.coroutines",
84+
URI.create("https://kotlinlang.org/api/kotlinx.coroutines/")
85+
)
86+
87+
// kotlin-serialization doc
88+
externalDocumentation(
89+
"kotlinx.serialization",
90+
URI.create("https://kotlinlang.org/api/kotlinx.serialization/")
91+
)
92+
93+
// ktor
94+
externalDocumentation(
95+
"ktor",
96+
URI.create("https://api.ktor.io/")
97+
)
98+
99+
// SLF4J
100+
externalDocumentation(
101+
"slf4j",
102+
URI.create("https://www.slf4j.org/apidocs/"),
103+
"element-list"
104+
)
105+
}
106+
107+
fun DokkaHtmlPluginParameters.configHtmlCustoms(project: Project) {
108+
customAssets.from(
109+
project.rootProject.file(".simbot/dokka-assets/logo-icon.svg"),
110+
project.rootProject.file(".simbot/dokka-assets/logo-icon-light.svg"),
111+
)
112+
113+
customStyleSheets.from(project.rootProject.file(".simbot/dokka-assets/css/kdoc-style.css"))
114+
115+
if (!isSimbotLocal()) {
116+
templatesDir.set(project.rootProject.file(".simbot/dokka-templates"))
117+
}
118+
119+
val now = Year.now().value
120+
footerMessage.set(
121+
"© 2024-$now " +
122+
"<a href='https://github.com/simple-robot'>Simple Robot</a>. All rights reserved."
123+
)
124+
125+
separateInheritedMembers.set(true)
126+
mergeImplicitExpectActualDeclarations.set(true)
127+
homepageLink.set(P.HOMEPAGE)
128+
}

buildSrc/src/main/kotlin/JsConfig.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,10 @@ inline fun KotlinJsTargetDsl.configJs(
2626
) {
2727
if (nodeJs) {
2828
nodejs()
29-
// {
30-
//// testTask {
31-
//// useMocha {
32-
//// timeout = "10000"
33-
//// }
34-
//// }
35-
// }
3629
}
3730

3831
if (browser) {
3932
browser()
40-
// {
41-
// testTask{
42-
// useKarma {
43-
// useChromeHeadless()
44-
// // useConfigDirectory(File(project.rootProject.projectDir, "karma"))
45-
// }
46-
// }
47-
// }
4833
}
4934

5035
binaries.library()

buildSrc/src/main/kotlin/kook-dokka-partial-configure.gradle.kts

Lines changed: 4 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -18,103 +18,13 @@
1818
* If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21-
import org.jetbrains.dokka.DokkaConfiguration
22-
import org.jetbrains.dokka.base.DokkaBase
23-
import org.jetbrains.dokka.base.DokkaBaseConfiguration
24-
import org.jetbrains.dokka.gradle.DokkaTaskPartial
25-
import java.net.URI
26-
import java.time.Year
27-
2821
plugins {
2922
id("org.jetbrains.dokka")
3023
}
3124

32-
33-
// dokka config
34-
tasks.withType<DokkaTaskPartial>().configureEach {
35-
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
36-
customAssets = listOf(
37-
rootProject.file(".simbot/dokka-assets/logo-icon.svg"),
38-
rootProject.file(".simbot/dokka-assets/logo-icon-light.svg"),
39-
)
40-
customStyleSheets = listOf(rootProject.file(".simbot/dokka-assets/css/kdoc-style.css"))
41-
if (!isSimbotLocal()) {
42-
templatesDir = rootProject.file(".simbot/dokka-templates")
43-
}
44-
footerMessage = "© 2021-${Year.now().value} <a href='https://github.com/simple-robot'>Simple Robot</a>. All rights reserved."
45-
separateInheritedMembers = true
46-
mergeImplicitExpectActualDeclarations = true
47-
homepageLink = P.HOMEPAGE
48-
}
49-
50-
dokkaSourceSets.configureEach {
51-
version = P.version
52-
documentedVisibilities.set(
53-
listOf(
54-
DokkaConfiguration.Visibility.PUBLIC,
55-
DokkaConfiguration.Visibility.PROTECTED
56-
)
57-
)
58-
fun checkModule(projectFileName: String): Boolean {
59-
val moduleMdFile = project.file(projectFileName)
60-
if (moduleMdFile.exists()) {
61-
moduleMdFile.useLines { lines ->
62-
val head = lines.first { it.isNotBlank() }.trim()
63-
if (head == "# Module ${project.name}") {
64-
includes.from(projectFileName)
65-
return true
66-
}
67-
}
68-
}
69-
70-
return false
71-
}
72-
73-
if (!checkModule("Module.md")) {
74-
checkModule("README.md")
75-
}
76-
77-
// samples
78-
// samples.from(
79-
// project.files(),
80-
// project.files("src/samples"),
81-
// )
82-
83-
sourceLink {
84-
localDirectory.set(projectDir.resolve("src"))
85-
val relativeTo = projectDir.relativeTo(rootProject.projectDir)
86-
.path
87-
.replace('\\', '/')
88-
89-
remoteUrl.set(URI.create("${P.HOMEPAGE}/tree/main/$relativeTo/src/").toURL())
90-
remoteLineSuffix.set("#L")
91-
}
92-
93-
94-
perPackageOption {
95-
matchingRegex.set(".*internal.*") // will match all .internal packages and sub-packages
96-
suppress.set(true)
97-
}
98-
99-
100-
fun externalDocumentation(docUri: URI) {
101-
externalDocumentationLink {
102-
url.set(docUri.toURL())
103-
packageListUrl.set(docUri.resolve("package-list").toURL())
104-
}
105-
}
106-
107-
// kotlin-coroutines doc
108-
externalDocumentation(URI.create("https://kotlinlang.org/api/kotlinx.coroutines/"))
109-
110-
// kotlin-serialization doc
111-
externalDocumentation(URI.create("https://kotlinlang.org/api/kotlinx.serialization/"))
112-
113-
// ktor
114-
externalDocumentation(URI.create("https://api.ktor.io/"))
115-
116-
// simbot doc
117-
externalDocumentation(URI.create("https://docs.simbot.forte.love/main-v4/"))
118-
25+
dokka {
26+
configSourceSets(project)
27+
pluginsConfiguration.html {
28+
configHtmlCustoms(project)
11929
}
12030
}

buildSrc/src/main/kotlin/kook-multiplatform-maven-publish.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ plugins {
2929
kotlin("multiplatform")
3030
signing
3131
`maven-publish`
32+
id("org.jetbrains.dokka")
3233
}
3334

3435

@@ -41,8 +42,8 @@ val jarJavadoc by tasks.registering(Jar::class) {
4142
group = "documentation"
4243
archiveClassifier.set("javadoc")
4344
if (!(isSnapshot || isSnapshot() || isSimbotLocal())) {
44-
dependsOn(tasks.dokkaHtml)
45-
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
45+
dependsOn(tasks.dokkaGeneratePublicationHtml)
46+
from(tasks.dokkaGeneratePublicationHtml.flatMap { it.outputDirectory })
4647
}
4748
}
4849

@@ -101,6 +102,3 @@ fun show() {
101102

102103
inline val Project.sourceSets: SourceSetContainer
103104
get() = extensions.getByName("sourceSets") as SourceSetContainer
104-
105-
internal val TaskContainer.dokkaHtml: TaskProvider<org.jetbrains.dokka.gradle.DokkaTask>
106-
get() = named<org.jetbrains.dokka.gradle.DokkaTask>("dokkaHtml")
Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2024. ForteScarlet.
2+
* Copyright (c) 2022-2025. ForteScarlet.
33
*
44
* This file is part of simbot-component-kook.
55
*
@@ -18,44 +18,30 @@
1818
* If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21-
import org.jetbrains.dokka.base.DokkaBase
22-
import org.jetbrains.dokka.base.DokkaBaseConfiguration
23-
import java.time.Year
24-
25-
26-
/*
27-
使用在根配置,配置dokka多模块
28-
*/
29-
3021
plugins {
3122
id("org.jetbrains.dokka")
3223
}
3324

34-
repositories {
35-
mavenCentral()
25+
dependencies {
26+
dokka(project(":simbot-component-kook-api"))
27+
dokka(project(":simbot-component-kook-stdlib"))
28+
dokka(project(":simbot-component-kook-core"))
3629
}
3730

38-
fun org.jetbrains.dokka.gradle.AbstractDokkaTask.configOutput(format: String) {
39-
moduleName.set("Simple Robot 组件 | KOOK")
40-
outputDirectory.set(rootProject.file("build/dokka/$format"))
41-
}
42-
43-
tasks.named<org.jetbrains.dokka.gradle.DokkaMultiModuleTask>("dokkaHtmlMultiModule") {
44-
configOutput("html")
31+
dokka {
32+
moduleName = "Simple Robot 组件 | KOOK"
4533

46-
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
47-
customAssets = listOf(
48-
rootProject.file(".simbot/dokka-assets/logo-icon.svg"),
49-
rootProject.file(".simbot/dokka-assets/logo-icon-light.svg"),
50-
)
51-
customStyleSheets = listOf(rootProject.file(".simbot/dokka-assets/css/kdoc-style.css"))
52-
if (!isSimbotLocal()) {
53-
templatesDir = rootProject.file(".simbot/dokka-templates")
34+
dokkaPublications.all {
35+
if (isSimbotLocal()) {
36+
logger.info("Is 'SIMBOT_LOCAL', offline")
37+
offlineMode = true
5438
}
55-
footerMessage = "© 2021-${Year.now().value} <a href='https://github.com/simple-robot'>Simple Robot</a>. All rights reserved."
56-
separateInheritedMembers = true
57-
mergeImplicitExpectActualDeclarations = true
58-
homepageLink = P.HOMEPAGE
39+
}
40+
41+
configSourceSets(project)
42+
43+
pluginsConfiguration.html {
44+
configHtmlCustoms(project)
5945
}
6046
}
6147

0 commit comments

Comments
 (0)