Skip to content

Commit dd02f2e

Browse files
Oleg review and adding multi-code blocks.
1 parent b58862e commit dd02f2e

File tree

2 files changed

+119
-55
lines changed

2 files changed

+119
-55
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ Learn more about Dokka plugins and their configuration in [Dokka plugins](https:
218218
If you want to learn how to develop Dokka plugins, see
219219
[Developer guides](https://kotlin.github.io/dokka/2.0.0/developer_guide/introduction/).
220220

221+
Dokka allows you to extend its functionality by [configuring custom plugins](https://github.com/Kotlin/dokka/blob/ae3840edb4e4afd7b3e3768a5fddfe8ec0e08f31/examples/gradle-v2/custom-dokka-plugin-example/demo-library/build.gradle.kts),
222+
which enable additional processing or modifications to the documentation generation process.
223+
221224
## Community
222225

223226
Dokka has a dedicated `#dokka` channel in [Kotlin Community Slack](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up)

docs/topics/dokka-migration.md

+116-55
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,16 @@ tasks.dokkaHtml {
127127

128128
New configuration:
129129

130+
Using `build.gradle.kts` files differs from using `.kt` files (such as custom plugins)
131+
due to the use of type-safe accessors in Kotlin DSL.
132+
133+
<tabs group="dokka-configuration">
134+
<tab title="Gradle configuration file" group-key="gradle">
135+
130136
```kotlin
137+
138+
// build.gradle.kts
139+
131140
dokka {
132141
moduleName.set("Project Name")
133142
dokkaSourceSets.main {
@@ -146,6 +155,38 @@ dokka {
146155
}
147156
```
148157

158+
</tab>
159+
<tab title="Kotlin file" group-key="kotlin">
160+
161+
```kotlin
162+
163+
// CustomPlugin.kt
164+
165+
class CustomPlugin : Plugin<Project> {
166+
override fun apply(project: Project) {
167+
project.extensions.configure<DokkaExtension> {
168+
dokkaSourceSets.named("main") {
169+
includes.from("README.md")
170+
sourceLink {
171+
localDirectory.set(project.file("src/main/kotlin"))
172+
remoteUrl.set(URI("https://example.com/src"))
173+
remoteLineSuffix.set("#L")
174+
}
175+
}
176+
177+
pluginsConfiguration.named<org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters>("pluginsConfiguration") {
178+
customStyleSheets.from("styles.css")
179+
customAssets.from("logo.png")
180+
footerMessage.set("(c) Your Company")
181+
}
182+
}
183+
}
184+
}
185+
```
186+
187+
</tab>
188+
</tabs>
189+
149190
#### Visibility settings
150191

151192
The `documentedVisibilities` property has changed from `Visibility.PUBLIC` to `VisibilityModifier.Public`.
@@ -206,8 +247,17 @@ Previous configuration:
206247

207248
New configuration:
208249

250+
Using `build.gradle.kts` files differs from using `.kt` files (such as custom plugins)
251+
due to the use of type-safe accessors in Kotlin DSL.
252+
253+
<tabs group="dokka-configuration">
254+
<tab title="Gradle configuration file" group-key="gradle">
255+
209256
```kotlin
210-
dokka {
257+
258+
// build.gradle.kts
259+
260+
dokka {
211261
moduleName.set("Project Name")
212262
dokkaSourceSets.main {
213263
includes.from("README.md")
@@ -220,6 +270,32 @@ New configuration:
220270
}
221271
```
222272

273+
</tab>
274+
<tab title="Kotlin file" group-key="kotlin">
275+
276+
```kotlin
277+
278+
// CustomPlugin.kt
279+
280+
class CustomPlugin : Plugin<Project> {
281+
override fun apply(project: Project) {
282+
project.extensions.configure<DokkaExtension> {
283+
dokkaSourceSets.named("main") {
284+
includes.from("README.md")
285+
sourceLink {
286+
localDirectory.set(project.file("src/main/kotlin"))
287+
remoteUrl.set(URI("https://example.com/src"))
288+
remoteLineSuffix.set("#L")
289+
}
290+
}
291+
}
292+
}
293+
}
294+
```
295+
296+
</tab>
297+
</tabs>
298+
223299
Given that the source link configuration has [changed](https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecated_invalid_url_decoding), the remote URL is now specified using the `URI` class instead of the `URL` class.
224300

225301
Previous configuration:
@@ -324,8 +400,10 @@ dokka {
324400

325401
#### Output directory for additional files
326402

327-
The ability to set an output directory and include additional files, such as `README.md`, is still supported in
328-
DGP v2. However, you have to now configure it under `dokkaPublications.html` in the `dokka {}` block of the root project.
403+
In DGP v2, the configuration for single-module and multi-module projects is now unified under the `dokka {}` block.
404+
Instead of configuring `dokkaHtml` and `dokkaHtmlMultiModule` tasks separately, you now specify settings inside the `dokkaPublications.html {}` block.
405+
406+
For multi-module projects, you can set the output directory and include additional files (such as `README.md`) in the `dokka {}` block of the root project.
329407

330408
Previous configuration:
331409

@@ -338,7 +416,16 @@ tasks.dokkaHtmlMultiModule {
338416

339417
New configuration:
340418

419+
Using `build.gradle.kts` files differs from using `.kt` files (such as custom plugins)
420+
due to the use of type-safe accessors in Kotlin DSL.
421+
422+
<tabs group="dokka-configuration">
423+
<tab title="Gradle configuration file" group-key="gradle">
424+
341425
```kotlin
426+
427+
// build.gradle.kts
428+
342429
dokka {
343430
dokkaPublications.html {
344431
outputDirectory.set(rootDir.resolve("docs/api/0.x"))
@@ -347,6 +434,28 @@ dokka {
347434
}
348435
```
349436

437+
</tab>
438+
<tab title="Kotlin file" group-key="kotlin">
439+
440+
```kotlin
441+
442+
// CustomPlugin.kt
443+
444+
class CustomPlugin : Plugin<Project> {
445+
override fun apply(project: Project) {
446+
project.extensions.configure<DokkaExtension> {
447+
dokkaPublications.named("html") {
448+
outputDirectory.set(project.rootDir.resolve("docs/api/0.x"))
449+
includes.from(project.layout.projectDirectory.file("README.md"))
450+
}
451+
}
452+
}
453+
}
454+
```
455+
456+
</tab>
457+
</tabs>
458+
350459
### Configure Dokka plugins
351460

352461
Configuring built-in Dokka plugins with JSON has been deprecated in favor of a type-safe DSL. This change improves compatibility
@@ -373,7 +482,9 @@ tasks.dokkaHtmlMultiModule {
373482

374483
New configuration:
375484

376-
DGP v2 replaces the JSON-based configuration with a type-safe DSL that is compatible with incremental builds.
485+
DGP v2 replaces the JSON-based configuration with a type-safe DSL that is compatible with incremental builds. See the
486+
configuration of [Dokka's versioning plugin example](https://github.com/Kotlin/dokka/tree/master/examples/gradle-v2/versioning-multimodule-example).
487+
377488
Use the `pluginsConfiguration{}` block to configure Dokka plugins in a type-safe way:
378489

379490
```kotlin
@@ -387,59 +498,9 @@ dokka {
387498
}
388499
```
389500

390-
### Configure custom Dokka plugins
391-
392-
Dokka 2.0.0 allows you to extend its functionality by configuring custom plugins,
501+
Dokka 2.0.0 allows you to extend its functionality by [configuring custom plugins](https://github.com/Kotlin/dokka/blob/ae3840edb4e4afd7b3e3768a5fddfe8ec0e08f31/examples/gradle-v2/custom-dokka-plugin-example/demo-library/build.gradle.kts),
393502
which enable additional processing or modifications to the documentation generation process.
394503

395-
To configure a custom Dokka plugin, implement a custom `DokkaPluginParametersBaseSpec`
396-
class in your `build.gradle.kts` file. The following example shows how to define and register a custom plugin parameter class:
397-
398-
```kotlin
399-
// build.gradle.kts
400-
401-
plugins {
402-
id("org.jetbrains.dokka") version "2.0.0"
403-
}
404-
405-
val dokkaScripts = layout.projectDirectory.dir("dokka-scripts")
406-
407-
dokka {
408-
pluginsConfiguration {
409-
registerBinding(DokkaScriptsPluginParameters::class, DokkaScriptsPluginParameters::class)
410-
register<DokkaScriptsPluginParameters>("DokkaScripts") {
411-
scripts.from(dokkaScripts.asFileTree)
412-
}
413-
}
414-
}
415-
416-
@OptIn(DokkaInternalApi::class)
417-
abstract class DokkaScriptsPluginParameters @Inject constructor(
418-
name: String
419-
) : DokkaPluginParametersBaseSpec(name, "example.dokkascript.plugin.DokkaScriptsPlugin") {
420-
421-
@get:InputFiles
422-
@get:PathSensitive(PathSensitivity.RELATIVE)
423-
@get:NormalizeLineEndings
424-
abstract val scripts: ConfigurableFileCollection
425-
426-
override fun jsonEncode(): String {
427-
val encodedScriptFiles = scripts.files.joinToString { "\"${it.canonicalFile.invariantSeparatorsPath}\"" }
428-
return """
429-
{
430-
"scripts": [ $encodedScriptFiles ]
431-
}
432-
""".trimIndent()
433-
}
434-
}
435-
```
436-
437-
If you need to reuse the plugin across multiple projects, consider moving the class to a shared location like `buildSrc` or a convention plugin.
438-
439-
> Currently, the `DokkaPluginParametersBaseSpec` implementation requires an opt-in for the internal Dokka Gradle API, but this restriction may be removed in the future.
440-
>
441-
{style="note"}
442-
443504
### Share Dokka configuration across modules
444505

445506
DPG v2 moves away from using `subprojects {}` or `allprojects {}` to share configuration across modules. In future Gradle versions,

0 commit comments

Comments
 (0)