1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
[//]: # (title: Dokka plugins)
Dokka was built from the ground up to be easily extensible and highly customizable, which allows the community
to implement plugins for missing or very specific features that are not provided out of the box.
Dokka plugins range anywhere from supporting other programming language sources to exotic output formats. You can add
support for your own KDoc tags or annotations, teach Dokka how to render different DSLs that are found in KDoc
descriptions, visually redesign Dokka's pages to be seamlessly integrated into your company's website, integrate it
with other tools and so much more.
If you want to learn how to create Dokka plugins, see
[Developer guides](https://kotlin.github.io/dokka/%dokkaVersion%/developer_guide/introduction/).
## Apply Dokka plugins
Dokka plugins are published as separate artifacts, so to apply a Dokka plugin you only need to add it as a dependency.
From there, the plugin extends Dokka by itself - no further action is needed.
> Plugins that use the same extension points or work in a similar way can interfere with each other.
> This may lead to visual bugs, general undefined behaviour or even failed builds. However, it should not lead to
> concurrency issues since Dokka does not expose any mutable data structures or objects.
>
> If you notice problems like this, it's a good idea to check which plugins are applied and what they do.
>
{type="note"}
Let's have a look at how you can apply the [mathjax plugin](https://github.com/Kotlin/dokka/tree/master/plugins/mathjax)
to your project:
<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">
The Gradle plugin for Dokka creates convenient dependency configurations that allow you to apply plugins universally or
for a specific output format only.
```kotlin
dependencies {
// Is applied universally
dokkaPlugin("org.jetbrains.dokka:mathjax-plugin:%dokkaVersion%")
// Is applied for the single-module dokkaHtml task only
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:%dokkaVersion%")
// Is applied for HTML format in multi-project builds
dokkaHtmlPartialPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:%dokkaVersion%")
}
```
> When documenting [multi-project](dokka-gradle.md#multi-project-builds) builds, you need to apply Dokka plugins within
> subprojects as well as in their parent project.
>
{type="note"}
</tab>
<tab title="Groovy" group-key="groovy">
The Gradle plugin for Dokka creates convenient dependency configurations that allow you to apply Dokka plugins universally or
for a specific output format only.
```groovy
dependencies {
// Is applied universally
dokkaPlugin 'org.jetbrains.dokka:mathjax-plugin:%dokkaVersion%'
// Is applied for the single-module dokkaHtml task only
dokkaHtmlPlugin 'org.jetbrains.dokka:kotlin-as-java-plugin:%dokkaVersion%'
// Is applied for HTML format in multi-project builds
dokkaHtmlPartialPlugin 'org.jetbrains.dokka:kotlin-as-java-plugin:%dokkaVersion%'
}
```
> When documenting [multi-project](dokka-gradle.md#multi-project-builds) builds, you need to apply Dokka plugins within
> subprojects as well as in their parent project.
>
{type="note"}
</tab>
<tab title="Maven" group-key="mvn">
```xml
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
...
<configuration>
<dokkaPlugins>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>mathjax-plugin</artifactId>
<version>%dokkaVersion%</version>
</plugin>
</dokkaPlugins>
</configuration>
</plugin>
```
</tab>
<tab title="CLI" group-key="cli">
If you are using the [CLI](dokka-cli.md) runner with [command line options](dokka-cli.md#run-with-command-line-options),
Dokka plugins should be passed as `.jar` files to `-pluginsClasspath`:
```Shell
java -jar dokka-cli-%dokkaVersion%.jar \
-pluginsClasspath "./dokka-base-%dokkaVersion%.jar;...;./mathjax-plugin-%dokkaVersion%.jar" \
...
```
If you are using [JSON configuration](dokka-cli.md#run-with-json-configuration), Dokka plugins should be specified under
`pluginsClasspath`.
```json
{
...
"pluginsClasspath": [
"./dokka-base-%dokkaVersion%.jar",
"...",
"./mathjax-plugin-%dokkaVersion%.jar"
],
...
}
```
</tab>
</tabs>
## Configure Dokka plugins
Dokka plugins can also have configuration options of their own. To see which options are available, consult
the documentation of the plugins you are using.
Let's have a look at how you can configure the `DokkaBase` plugin, which is responsible for generating [HTML](dokka-html.md)
documentation, by adding a custom image to the assets (`customAssets` option), by adding custom style sheets
(`customStyleSheets` option), and by modifying the footer message (`footerMessage` option):
<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">
Gradle's Kotlin DSL allows for type-safe plugin configuration. This is achievable by adding the plugin's artifact to
the classpath dependencies in the `buildscript` block, and then importing plugin and configuration classes:
```kotlin
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.base.DokkaBaseConfiguration
buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-base:%dokkaVersion%")
}
}
tasks.withType<DokkaTask>().configureEach {
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
customAssets = listOf(file("my-image.png"))
customStyleSheets = listOf(file("my-styles.css"))
footerMessage = "(c) 2022 MyOrg"
}
}
```
Alternatively, plugins can be configured via JSON. With this method, no additional dependencies are needed.
```kotlin
import org.jetbrains.dokka.gradle.DokkaTask
tasks.withType<DokkaTask>().configureEach {
val dokkaBaseConfiguration = """
{
"customAssets": ["${file("assets/my-image.png")}"],
"customStyleSheets": ["${file("assets/my-styles.css")}"],
"footerMessage": "(c) 2022 MyOrg"
}
"""
pluginsMapConfiguration.set(
mapOf(
// fully qualified plugin name to json configuration
"org.jetbrains.dokka.base.DokkaBase" to dokkaBaseConfiguration
)
)
}
```
</tab>
<tab title="Groovy" group-key="groovy">
```groovy
import org.jetbrains.dokka.gradle.DokkaTask
tasks.withType(DokkaTask.class) {
String dokkaBaseConfiguration = """
{
"customAssets": ["${file("assets/my-image.png")}"],
"customStyleSheets": ["${file("assets/my-styles.css")}"],
"footerMessage": "(c) 2022 MyOrg"
}
"""
pluginsMapConfiguration.set(
// fully qualified plugin name to json configuration
["org.jetbrains.dokka.base.DokkaBase": dokkaBaseConfiguration]
)
}
```
</tab>
<tab title="Maven" group-key="mvn">
```xml
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
...
<configuration>
<pluginsConfiguration>
<!-- Fully qualified plugin name -->
<org.jetbrains.dokka.base.DokkaBase>
<!-- Options by name -->
<customAssets>
<asset>${project.basedir}/my-image.png</asset>
</customAssets>
<customStyleSheets>
<stylesheet>${project.basedir}/my-styles.css</stylesheet>
</customStyleSheets>
<footerMessage>(c) MyOrg 2022 Maven</footerMessage>
</org.jetbrains.dokka.base.DokkaBase>
</pluginsConfiguration>
</configuration>
</plugin>
```
</tab>
<tab title="CLI" group-key="cli">
If you are using the [CLI](dokka-cli.md) runner with [command line options](dokka-cli.md#run-with-command-line-options),
use the `-pluginsConfiguration` option that accepts JSON configuration in the form of `fullyQualifiedPluginName=json`.
If you need to configure multiple plugins, you can pass multiple values separated by `^^`.
```Bash
java -jar dokka-cli-%dokkaVersion%.jar \
...
-pluginsConfiguration "org.jetbrains.dokka.base.DokkaBase={\"customAssets\": [\"my-image.png\"], \"customStyleSheets\": [\"my-styles.css\"], \"footerMessage\": \"(c) 2022 MyOrg CLI\"}"
```
If you are using [JSON configuration](dokka-cli.md#run-with-json-configuration), there exists a similar
`pluginsConfiguration` array that accepts JSON configuration in `values`.
```json
{
"moduleName": "Dokka Example",
"pluginsConfiguration": [
{
"fqPluginName": "org.jetbrains.dokka.base.DokkaBase",
"serializationFormat": "JSON",
"values": "{\"customAssets\": [\"my-image.png\"], \"customStyleSheets\": [\"my-styles.css\"], \"footerMessage\": \"(c) 2022 MyOrg\"}"
}
]
}
```
</tab>
</tabs>
## Notable plugins
Here are some notable Dokka plugins that you might find useful:
| **Name** | **Description** |
|-----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [Android documentation plugin](https://github.com/Kotlin/dokka/tree/master/plugins/android-documentation) | Improves the documentation experience on Android |
| [Versioning plugin](https://github.com/Kotlin/dokka/tree/master/plugins/versioning) | Adds version selector and helps to organize documentation for different versions of your application/library |
| [MermaidJS HTML plugin](https://github.com/glureau/dokka-mermaid) | Renders [MermaidJS](https://mermaid-js.github.io/mermaid/#/) diagrams and visualizations found in KDocs |
| [Mathjax HTML plugin](https://github.com/Kotlin/dokka/tree/master/plugins/mathjax) | Pretty prints mathematics found in KDocs |
| [Kotlin as Java plugin](https://github.com/Kotlin/dokka/tree/master/plugins/kotlin-as-java) | Renders Kotlin signatures as seen from Java's perspective |
If you are a Dokka plugin author and would like to add your plugin to this list, get in touch with maintainers
via [Slack](dokka-introduction.md#community) or [GitHub](https://github.com/Kotlin/dokka/).
<a href="https://surveys.jetbrains.com/s3/dokka-survey">
<img src="dokka-devx-survey-banner.png" width="700" alt="Dokka devX survey"/>
</a>
|