Skip to content

Commit a3427b8

Browse files
authored
Merge pull request #1030 from simple-robot/improve-dokka
优化Dokka配置
2 parents 5d64c6c + e25f03b commit a3427b8

File tree

8 files changed

+209
-145
lines changed

8 files changed

+209
-145
lines changed

build.gradle.kts

Lines changed: 6 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ import changelog.GenerateChangelogTask
2525
import changelog.GenerateSubChangelogTask
2626
import love.forte.plugin.suspendtrans.*
2727
import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension
28-
import org.jetbrains.dokka.gradle.DokkaExtension
29-
import org.jetbrains.dokka.gradle.engine.parameters.DokkaSourceSetSpec
30-
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier
31-
import java.net.URI
32-
import java.time.Year
3328

3429
plugins {
3530
idea
@@ -402,109 +397,16 @@ subprojects {
402397
val p = this
403398
if (plugins.hasPlugin(libs.plugins.dokka.get().pluginId)) {
404399
dokka {
405-
dokkaSourceSets.configureEach {
406-
configModuleMdInclude(p)
407-
configSourceLink(p)
408-
configExternalDocumentations()
400+
configSourceSets(p)
401+
pluginsConfiguration.html {
402+
configHtmlCustoms(p)
409403
}
410-
configHtmlCustom()
411404
}
412405
rootProject.dependencies.dokka(p)
413406
}
414407
}
415408
}
416409

417-
fun DokkaSourceSetSpec.configModuleMdInclude(project: Project) {
418-
val moduleFile = project.file("Module.md")
419-
if (moduleFile.exists() && moduleFile.length() > 0) {
420-
includes.from("Module.md")
421-
}
422-
}
423-
424-
fun DokkaSourceSetSpec.configSourceLink(project: Project) {
425-
sourceLink {
426-
localDirectory.set(File(project.projectDir, "src"))
427-
val relativeTo = project.projectDir.relativeTo(rootProject.projectDir).toString()
428-
.replace('\\', '/')
429-
// remoteUrl.set(URI.create("${P.HOMEPAGE}/tree/v4-dev/$relativeTo/src/").toURL())
430-
remoteUrl.set(URI.create("${P.HOMEPAGE}/tree/v4-dev/$relativeTo/src"))
431-
remoteLineSuffix.set("#L")
432-
}
433-
}
434-
435-
fun DokkaSourceSetSpec.configExternalDocumentations() {
436-
fun externalDocumentation(name: String, docUrl: URI, suffix: String = "package-list") {
437-
externalDocumentationLinks.register(name) {
438-
url.set(docUrl)
439-
packageListUrl.set(docUrl.resolve(suffix))
440-
}
441-
}
442-
443-
// kotlin-coroutines doc
444-
externalDocumentation(
445-
"kotlinx.coroutines",
446-
URI.create("https://kotlinlang.org/api/kotlinx.coroutines/")
447-
)
448-
449-
// kotlin-serialization doc
450-
externalDocumentation(
451-
"kotlinx.serialization",
452-
URI.create("https://kotlinlang.org/api/kotlinx.serialization/")
453-
)
454-
455-
// ktor
456-
externalDocumentation(
457-
"ktor",
458-
URI.create("https://api.ktor.io/")
459-
)
460-
461-
// SLF4J
462-
externalDocumentation(
463-
"slf4j",
464-
URI.create("https://www.slf4j.org/apidocs/"),
465-
"element-list"
466-
)
467-
468-
// Spring Framework
469-
// TODO 准确的版本号?
470-
externalDocumentation(
471-
"spring-framework",
472-
URI.create("https://docs.spring.io/spring-framework/docs/current/javadoc-api/"),
473-
"element-list"
474-
)
475-
476-
// Spring Boot
477-
externalDocumentation(
478-
"spring-boot",
479-
URI.create("https://docs.spring.io/spring-boot/docs/${libs.versions.spring.boot.v3.get()}/api/"),
480-
"element-list"
481-
)
482-
}
483-
484-
fun DokkaExtension.configHtmlCustom() {
485-
pluginsConfiguration.html {
486-
customAssets.from(
487-
rootProject.file(".simbot/dokka-assets/logo-icon.svg"),
488-
rootProject.file(".simbot/dokka-assets/logo-icon-light.svg"),
489-
)
490-
491-
customStyleSheets.from(rootProject.file(".simbot/dokka-assets/css/kdoc-style.css"))
492-
493-
if (!isSimbotLocal()) {
494-
templatesDir = rootProject.file(".simbot/dokka-templates")
495-
}
496-
497-
footerMessage =
498-
"© 2021-${Year.now().value} " +
499-
"<a href='https://github.com/simple-robot'>Simple Robot</a>. " +
500-
"All rights reserved."
501-
502-
separateInheritedMembers = true
503-
mergeImplicitExpectActualDeclarations = true
504-
homepageLink = P.HOMEPAGE
505-
}
506-
}
507-
508410
dokka {
509411
moduleName = "Simple Robot"
510412

@@ -515,32 +417,10 @@ dokka {
515417
}
516418
}
517419

518-
dokkaSourceSets.configureEach {
519-
skipEmptyPackages = true
520-
suppressGeneratedFiles = false
521-
522-
documentedVisibilities(
523-
VisibilityModifier.Public,
524-
VisibilityModifier.Protected
525-
)
526-
527-
tasks.withType(JavaCompile::class.java).firstOrNull()
528-
?.targetCompatibility?.toInt().also {
529-
logger.info("project {} found jdkVersionValue: {}", project, it)
530-
}?.also {
531-
jdkVersion = it
532-
}
533-
534-
configModuleMdInclude(project)
535-
536-
perPackageOption {
537-
matchingRegex.set(".*internal.*") // will match all .internal packages and sub-packages
538-
suppress.set(true)
539-
}
420+
configSourceSets(project)
540421

541-
configExternalDocumentations()
422+
pluginsConfiguration.html {
423+
configHtmlCustoms(project)
542424
}
543-
544-
configHtmlCustom()
545425
}
546426
// endregion
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
* Copyright (c) 2025. ForteScarlet.
3+
*
4+
* Project https://github.com/simple-robot/simpler-robot
5+
6+
*
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
import org.gradle.api.Project
25+
import org.gradle.api.artifacts.VersionCatalog
26+
import org.gradle.api.artifacts.VersionCatalogsExtension
27+
import org.gradle.api.plugins.ExtensionAware
28+
import org.gradle.api.tasks.compile.JavaCompile
29+
import org.gradle.kotlin.dsl.getByType
30+
import org.jetbrains.dokka.gradle.DokkaExtension
31+
import org.jetbrains.dokka.gradle.engine.parameters.DokkaSourceSetSpec
32+
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier
33+
import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters
34+
import java.io.File
35+
import java.net.URI
36+
import java.time.Year
37+
import kotlin.jvm.optionals.getOrElse
38+
39+
40+
fun DokkaExtension.configSourceSets(project: Project) {
41+
dokkaSourceSets.configureEach {
42+
skipEmptyPackages.set(true)
43+
suppressGeneratedFiles.set(false)
44+
documentedVisibilities(
45+
VisibilityModifier.Public,
46+
VisibilityModifier.Protected
47+
)
48+
val targetCompatibility = project.tasks.withType(JavaCompile::class.java).firstOrNull()?.targetCompatibility
49+
50+
logger.info("project {} found jdkVersionValue: {}", project, targetCompatibility)
51+
52+
when (targetCompatibility) {
53+
"1.8" -> {
54+
jdkVersion.set(8)
55+
}
56+
null -> {
57+
// Do nothing here.
58+
}
59+
else -> {
60+
jdkVersion.set(targetCompatibility.toInt())
61+
}
62+
}
63+
64+
configModuleMdInclude(project)
65+
66+
perPackageOption {
67+
matchingRegex.set(".*internal.*") // will match all .internal packages and sub-packages
68+
suppress.set(true)
69+
}
70+
71+
configSourceLink(project)
72+
73+
configExternalDocumentations(project)
74+
}
75+
}
76+
77+
fun DokkaSourceSetSpec.configModuleMdInclude(project: Project) {
78+
val moduleFile = project.file("Module.md")
79+
if (moduleFile.exists() && moduleFile.length() > 0) {
80+
includes.from("Module.md")
81+
}
82+
}
83+
84+
fun DokkaSourceSetSpec.configSourceLink(project: Project) {
85+
sourceLink {
86+
localDirectory.set(File(project.projectDir, "src"))
87+
val relativeTo = project.projectDir.relativeTo(project.rootProject.projectDir).toString()
88+
.replace('\\', '/')
89+
remoteUrl.set(URI.create("${P.HOMEPAGE}/tree/dev/main/$relativeTo/src"))
90+
remoteLineSuffix.set("#L")
91+
}
92+
}
93+
94+
fun DokkaSourceSetSpec.configExternalDocumentations(project: Project) {
95+
fun externalDocumentation(name: String, docUrl: URI, suffix: String = "package-list") {
96+
externalDocumentationLinks.register(name) {
97+
url.set(docUrl)
98+
packageListUrl.set(docUrl.resolve(suffix))
99+
}
100+
}
101+
102+
// kotlin-coroutines doc
103+
externalDocumentation(
104+
"kotlinx.coroutines",
105+
URI.create("https://kotlinlang.org/api/kotlinx.coroutines/")
106+
)
107+
108+
// kotlin-serialization doc
109+
externalDocumentation(
110+
"kotlinx.serialization",
111+
URI.create("https://kotlinlang.org/api/kotlinx.serialization/")
112+
)
113+
114+
// ktor
115+
externalDocumentation(
116+
"ktor",
117+
URI.create("https://api.ktor.io/")
118+
)
119+
120+
// SLF4J
121+
externalDocumentation(
122+
"slf4j",
123+
URI.create("https://www.slf4j.org/apidocs/"),
124+
"element-list"
125+
)
126+
127+
// Spring Framework
128+
// TODO 准确的版本号?
129+
externalDocumentation(
130+
"spring-framework",
131+
URI.create("https://docs.spring.io/spring-framework/docs/current/javadoc-api/"),
132+
"element-list"
133+
)
134+
135+
val versionCatalog: VersionCatalog = project.versionCatalog()
136+
137+
val springBootV3Version = versionCatalog.findVersion("spring-boot-v3")
138+
.map { it.toString() }
139+
.getOrElse { "current" }
140+
141+
println("springBootV3Version: $springBootV3Version")
142+
143+
// Spring Boot
144+
externalDocumentation(
145+
"spring-boot",
146+
URI.create("https://docs.spring.io/spring-boot/docs/$springBootV3Version/api/"),
147+
"element-list"
148+
)
149+
}
150+
151+
fun DokkaHtmlPluginParameters.configHtmlCustoms(project: Project) {
152+
customAssets.from(
153+
project.rootProject.file(".simbot/dokka-assets/logo-icon.svg"),
154+
project.rootProject.file(".simbot/dokka-assets/logo-icon-light.svg"),
155+
)
156+
157+
customStyleSheets.from(project.rootProject.file(".simbot/dokka-assets/css/kdoc-style.css"))
158+
159+
if (!isSimbotLocal()) {
160+
templatesDir.set(project.rootProject.file(".simbot/dokka-templates"))
161+
}
162+
163+
val now = Year.now().value
164+
footerMessage.set(
165+
"© 2024-$now " +
166+
"<a href='https://github.com/simple-robot'>Simple Robot</a>. All rights reserved."
167+
)
168+
169+
separateInheritedMembers.set(true)
170+
mergeImplicitExpectActualDeclarations.set(true)
171+
homepageLink.set(P.HOMEPAGE)
172+
}
173+
174+
private fun ExtensionAware.versionCatalog(name: String = "libs"): VersionCatalog {
175+
return extensions.getByType<VersionCatalogsExtension>().named(name)
176+
}

gradle.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ kotlin.mpp.stability.nowarn=true
2929
# To hide this message, add 'kotlin.native.ignoreDisabledTargets=true' to the Gradle properties.
3030
kotlin.native.ignoreDisabledTargets=true
3131

32-
# Such dependencies are not applicable for Kotlin/Native, consider changing the dependency type to 'implementation' or 'api'.
33-
# To disable this warning, set the kotlin.native.ignoreIncorrectDependencies=true project property
34-
kotlin.native.ignoreIncorrectDependencies=true
35-
3632
# 'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. You can use -Xexpect-actual-classes flag to suppress this warning. Also see: https://youtrack.jetbrains.com/issue/KT-61573
3733
# "-Xexpect-actual-classes"
3834
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=1G -Dfile.encoding=UTF-8

simbot-cores/simbot-core/src/commonTest/kotlin/love/forte/simbot/core/application/ApplicationEventDispatcherTests.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* Copyright (c) 2024. ForteScarlet.
2+
* Copyright (c) 2024-2025. ForteScarlet.
33
*
44
* Project https://github.com/simple-robot/simpler-robot
55
66
*
7-
* This file is part of the Simple Robot Library.
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
88
*
99
* This program is free software: you can redistribute it and/or modify
1010
* it under the terms of the GNU Lesser General Public License as published by
@@ -108,6 +108,7 @@ class ApplicationEventDispatcherTests {
108108

109109
}
110110

111+
@OptIn(FuzzyEventTypeImplementation::class)
111112
private class MyEvent : Event {
112113
override val id: ID = UUID.random()
113114

0 commit comments

Comments
 (0)