# Maven
To generate documentation for a Maven-based project, you can use the Maven plugin for Dokka.
Note:
Compared to the [Gradle plugin for Dokka](dokka-gradle.html), the Maven plugin has only basic features and
does not provide support for multi-module builds.
You can play around with Dokka and see how it can be configured for a Maven project by visiting
our [Maven example](https://github.com/Kotlin/dokka/tree/2.2.0/examples/maven) project.
## Apply Dokka
To apply Dokka, you need to add `dokka-maven-plugin` to the `plugins` section of your POM file:
```XML
org.jetbrains.dokkadokka-maven-plugin2.2.0pre-sitedokka
```
## Generate documentation
The following goals are provided by the Maven plugin:
| Goal |Description |
---------------------
| `dokka:dokka` |Generates documentation with Dokka plugins applied. [HTML](dokka-html.html) format by default. |
### Experimental
| Goal |Description |
---------------------
| `dokka:javadoc` |Generates documentation in [Javadoc](dokka-javadoc.html) format. |
| `dokka:javadocJar` |Generates a `javadoc.jar` file that contains documentation in [Javadoc](dokka-javadoc.html) format. |
### Other output formats
By default, the Maven plugin for Dokka builds documentation in [HTML](dokka-html.html) output format.
All other output formats are implemented as [Dokka plugins](dokka-plugins.html). In order to generate documentation in the
desired format, you have to add it as a Dokka plugin to the configuration.
For example, to use the experimental [GFM](https://github.com/Kotlin/dokka/tree/master/dokka-subprojects/plugin-gfm#readme) format, you have to add `gfm-plugin` artifact:
```XML
org.jetbrains.dokkadokka-maven-plugin
...
org.jetbrains.dokkagfm-plugin2.2.0
```
With this configuration, running the `dokka:dokka` goal produces documentation in GFM format.
To learn more about Dokka plugins, see [Dokka plugins](dokka-plugins.html).
## Build javadoc.jar
If you want to publish your library to a repository, you may need to provide a `javadoc.jar` file that contains
API reference documentation of your library.
For example, if you want to publish to [Maven Central](https://central.sonatype.org/), you
[must](https://central.sonatype.org/publish/requirements/) supply a `javadoc.jar` alongside your project. However,
not all repositories have that rule.
Unlike the [Gradle plugin for Dokka](dokka-gradle.html#build-javadoc-jar), the Maven plugin comes with a ready-to-use `dokka:javadocJar`
goal. By default, it generates documentation in [Javadoc](dokka-javadoc.html) output format in the`target` folder.
If you are not satisfied with the built-in goal or want to customize the output (for example, you want to generate
documentation in [HTML](dokka-html.html) format instead of Javadoc), similar behavior can be achieved by adding the
Maven JAR plugin with the following configuration:
```XML
org.apache.maven.pluginsmaven-jar-plugin3.3.0test-jardokka-jarpackagejardokka${project.build.directory}/dokkatrue
```
The documentation and the `.jar` archive for it are then generated by running `dokka:dokka` and `jar:jar@dokka-jar` goals:
```BASH
mvn dokka:dokka jar:jar@dokka-jar
```
Tip:
If you publish your library to Maven Central, you can use services like [javadoc.io](https://javadoc.io/) to
host your library's API documentation for free and without any setup. It takes documentation pages straight
from the `javadoc.jar`. It works well with the HTML format as demonstrated in
[this example](https://javadoc.io/doc/com.trib3/server/latest/index.html).
## Configuration example
Maven's plugin configuration block can be used to configure Dokka.
Here is an example of a basic configuration that only changes the output location of your documentation:
```XML
org.jetbrains.dokkadokka-maven-plugin
...
${project.basedir}/target/documentation/dokka
```
## Configuration options
Dokka has many configuration options to tailor your and your reader's experience.
Below are some examples and detailed descriptions for each configuration section. You can also find an example
with [all configuration options](#complete-configuration) applied at the bottom of the page.
### General configuration
```XML
org.jetbrains.dokkadokka-maven-pluginfalse${project.artifactId}${project.basedir}/target/documentationfalsetruefalsefalse${project.basedir}/srcPUBLICPROTECTEDfalsefalsetrue/path/to/dir/path/to/filecom.example.SuppressMe81.71.7falsefalsepackages.mdextra.md${project.compileClasspathElements}${project.basedir}/samples
```
skip
: Whether to skip documentation generation.
: Default: `false`
moduleName
: The display name used to refer to the project/module. It's used for the table of contents, navigation, logging, etc.
: Default: `{project.artifactId}`
outputDir
: The directory to where documentation is generated, regardless of format.
: Default: `{project.basedir}/target/dokka`
failOnWarning
: Whether to fail documentation generation if Dokka has emitted a warning or an error. The process waits until
all errors and warnings have been emitted first.
: This setting works well with `reportUndocumented`.
: Default: `false`
suppressObviousFunctions
: Whether to suppress obvious functions.
: A function is considered to be obvious if it is:
: * Inherited from `kotlin.Any`, `Kotlin.Enum`, `java.lang.Object` or `java.lang.Enum`, such as `equals`, `hashCode`, `toString`.
* Synthetic (generated by the compiler) and does not have any documentation, such as `dataClass.componentN` or `dataClass.copy`.
: Default: `true`
suppressInheritedMembers
: Whether to suppress inherited members that aren't explicitly overridden in a given class.
: Note: This can suppress functions such as `equals`/`hashCode`/`toString`,
but cannot suppress synthetic functions such as `dataClass.componentN` and
`dataClass.copy`. Use `suppressObviousFunctions` for that.
: Default: `false`
offlineMode
: Whether to resolve remote files/links over your network.
: This includes package-lists used for generating external documentation links.
For example, to make classes from the standard library clickable.
: Setting this to `true` can significantly speed up build times in certain cases,
but can also worsen documentation quality and user experience. For example, by
not resolving class/member links from your dependencies, including the standard library.
: Note: You can cache fetched files locally and provide them to
Dokka as local paths. See `externalDocumentationLinks` section.
: Default: `false`
sourceDirectories
: The source code roots to be analyzed and documented.
Acceptable inputs are directories and individual `.kt` / `.java` files.
: Default: `{project.compileSourceRoots}`
documentedVisibilities
: The set of visibility modifiers that should be documented.
: This can be used if you want to document `protected`/`internal`/`private` declarations,
as well as if you want to exclude `public` declarations and only document internal API.
: Can be configured on per-package basis.
: Default: `PUBLIC`
reportUndocumented
: Whether to emit warnings about visible undocumented declarations, that is declarations without KDocs
after they have been filtered by `documentedVisibilities` and other filters.
: This setting works well with `failOnWarning`.
: This can be overridden at package level.
: Default: `false`
skipDeprecated
: Whether to document declarations annotated with `@Deprecated`.
: This can be overridden at package level.
: Default: `false`
skipEmptyPackages
: Whether to skip packages that contain no visible declarations after
various filters have been applied.
: For example, if `skipDeprecated` is set to `true` and your package contains only
deprecated declarations, it is considered to be empty.
: Default: `true`
suppressedFiles
: The directories or individual files that should be suppressed, meaning that declarations from them
are not documented.
suppressAnnotatedWith
: A list of annotation fully qualified names (FQNs) to suppress declarations annotated with.
: Any declaration annotated with one of these annotations is excluded from the generated documentation.
jdkVersion
: The JDK version to use when generating external documentation links for Java types.
: For example, if you use `java.util.UUID` in some public declaration signature,
and this option is set to `8`, Dokka generates an external documentation link
to [JDK 8 Javadocs](https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html) for it.
: Default: JDK 8
languageVersion
: [The Kotlin language version](https://kotlinlang.org/docs/compatibility-modes.html)
used for setting up analysis and [@sample](https://kotlinlang.org/docs/kotlin-doc.html#sample-identifier)
environment.
: By default, the latest language version available to Dokka's embedded compiler is used.
apiVersion
: [The Kotlin API version](https://kotlinlang.org/docs/compatibility-modes.html)
used for setting up analysis and [@sample](https://kotlinlang.org/docs/kotlin-doc.html#sample-identifier)
environment.
: By default, it is deduced from `languageVersion`.
noStdlibLink
: Whether to generate external documentation links that lead to the API reference
documentation of Kotlin's standard library.
: Note: Links are generated when `noStdLibLink` is set to `false`.
: Default: `false`
noJdkLink
: Whether to generate external documentation links to JDK's Javadocs.
: The version of JDK Javadocs is determined by the `jdkVersion` option.
: Note: Links are generated when `noJdkLink` is set to `false`.
: Default: `false`
includes
: A list of Markdown files that contain
[module and package documentation](dokka-module-and-package-docs.html)
: The contents of specified files are parsed and embedded into documentation as module and package descriptions.
classpath
: The classpath for analysis and interactive samples.
: This is useful if some types that come from dependencies are not resolved/picked up automatically.
This option accepts both `.jar` and `.klib` files.
: Default: `{project.compileClasspathElements}`
samples
: A list of directories or files that contain sample functions which are referenced via
[@sample KDoc tag.](https://kotlinlang.org/docs/kotlin-doc.html#sample-identifier)
### Source link configuration
The `sourceLinks` configuration block allows you to add a `source` link to each signature
that leads to the `url` with a specific line number. (The line number is configurable by setting `lineSuffix`).
This helps readers to find the source code for each declaration.
For an example, see the documentation for the
[count()](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/count.html)
function in `kotlinx.coroutines`.
```XML
org.jetbrains.dokkadokka-maven-pluginsrchttps://github.com/kotlin/dokka/tree/master/src#L
```
path
: The path to the local source directory. The path must be relative to the root of the
current module.
: Note: Only Unix based paths are allowed, Windows-style paths will throw an error.
url
: The URL of the source code hosting service that can be accessed by documentation readers,
like GitHub, GitLab, Bitbucket, etc. This URL is used to generate
source code links of declarations.
lineSuffix
: The suffix used to append source code line number to the URL. This helps readers navigate not only
to the file, but to the specific line number of the declaration.
: The number itself is appended to the specified suffix. For example, if this option is set
to `#L` and the line number is 10, the resulting URL suffix is `#L10`.
: Suffixes used by popular services:
: * GitHub: `#L`
* GitLab: `#L`
* Bitbucket: `#lines-`
### External documentation links configuration
The `externalDocumentationLinks` block allows the creation of links that lead to the externally hosted documentation of
your dependencies.
For example, if you are using types from `kotlinx.serialization`, by default they are unclickable in your
documentation, as if they are unresolved. However, since the API reference documentation for `kotlinx.serialization`
is built by Dokka and is [published on kotlinlang.org](https://kotlinlang.org/api/kotlinx.serialization/), you can
configure external documentation links for it. Thus allowing Dokka to generate links for types from the library, making
them resolve successfully and clickable.
By default, external documentation links for Kotlin standard library and JDK are configured.
```XML
org.jetbrains.dokkadokka-maven-pluginhttps://kotlinlang.org/api/kotlinx.serialization/file:/${project.basedir}/serialization.package.list
```
url
: The root URL of documentation to link to. It must contain a trailing slash.
: Dokka does its best to automatically find the `package-list` for the given URL,
and link declarations together.
: If automatic resolution fails or if you want to use locally cached files instead,
consider setting the `packageListUrl` option.
packageListUrl
: The exact location of a `package-list`. This is an alternative to relying on Dokka
automatically resolving it.
: Package lists contain information about the documentation and the project itself,
such as module and package names.
: This can also be a locally cached file to avoid network calls.
### Package options
The `perPackageOptions` configuration block allows setting some options for specific packages matched by `matchingRegex`.
```XML
org.jetbrains.dokkadokka-maven-plugin.*api.*falsefalsefalsePUBLICPRIVATEPROTECTEDINTERNALPACKAGE
```
matchingRegex
: The regular expression that is used to match the package.
: Default: `.*`
suppress
: Whether this package should be skipped when generating documentation.
: Default: `false`
documentedVisibilities
: The set of visibility modifiers that should be documented.
: This can be used if you want to document `protected`/`internal`/`private` declarations within this package,
as well as if you want to exclude `public` declarations and only document internal API.
: Default: `PUBLIC`
skipDeprecated
: Whether to document declarations annotated with `@Deprecated`.
: This can be set on project/module level.
: Default: `false`
reportUndocumented
: Whether to emit warnings about visible undocumented declarations, that is declarations without KDocs
after they have been filtered by `documentedVisibilities` and other filters.
: This setting works well with `failOnWarning`.
: Default: `false`
### Complete configuration
Below you can see all the possible configuration options applied at the same time.
```XML
org.jetbrains.dokkadokka-maven-pluginfalse${project.artifactId}${project.basedir}/target/documentationfalsetruefalsefalse${project.basedir}/srcPUBLICPRIVATEPROTECTEDINTERNALPACKAGEfalsefalsetrue/path/to/dir/path/to/file81.71.7falsefalsepackages.mdextra.md${project.compileClasspathElements}${project.basedir}/samplessrchttps://github.com/kotlin/dokka/tree/master/src#Lhttps://kotlinlang.org/api/core/kotlin-stdlib/file:/${project.basedir}/stdlib.package.list.*api.*falsefalsefalsePUBLICPRIVATEPROTECTEDINTERNALPACKAGE
```