@@ -25,7 +25,13 @@ import org.gradle.api.provider.Provider
25
25
import org.gradle.kotlin.dsl.assign
26
26
import org.gradle.kotlin.dsl.withType
27
27
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
28
+ import org.jetbrains.dokka.gradle.DokkaExtension
29
+ import org.jetbrains.dokka.gradle.DokkaTask
28
30
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
29
35
import java.net.URI
30
36
import java.net.URL
31
37
@@ -35,18 +41,27 @@ fun Project.configureDokka(
35
41
dokkaOverrideTarget : Provider <String ?>
36
42
) {
37
43
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
+ }
38
49
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)
43
53
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)
47
62
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() )
50
65
}
51
66
}
52
67
}
@@ -123,3 +138,75 @@ private fun Project.configureDokkaSourceSet(
123
138
logger.warn(" Sourceset ${project.name} :${sourceSet.name} suppressed" )
124
139
}
125
140
}
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
+ }
0 commit comments