Dokka Gradle configuration options
Dokka has many configuration options to customize your and your reader's experience.
Below are detailed descriptions for each configuration section and some examples. You can also find an example with all configuration options applied.
For more details on applying configuration blocks for single-project and multi-project builds, see Configuration examples.
General configuration
Here is an example of the general Dokka Gradle plugin configuration:
Use the top-level
dokka {}DSL configuration.In DGP, you declare Dokka publication configurations in the
dokkaPublications{}block.The syntax of
build.gradle.ktsfiles differs from regular.ktfiles (such as those used for Kotlin custom plugins) because Gradle's Kotlin DSL uses type-safe accessors.
For more information about working with files, see the Gradle docs.
- moduleName
The display name for the project’s documentation. It appears in the table of contents, navigation, headers, and log messages. In multi-project builds, each subproject's
moduleNameis used as its section title in aggregated documentation.Default: Gradle project name
- moduleVersion
The subproject version displayed in the generated documentation. In single-project builds, it is used as the project version. In multi-project builds, each subproject's
moduleVersionis used when aggregating documentation.Default: Gradle project version
- outputDirectory
The directory where the generated documentation is stored.
This setting applies to all documentation formats (HTML, Javadoc, etc.) generated by the
dokkaGeneratetask.Default:
build/dokka/htmlOutput directory for additional files
You can specify the output directory and include additional files for both single and multi-project builds. For multi-project builds, set the output directory and include additional files in the configuration of the root project.
- failOnWarning
Determines whether Dokka should fail the build when a warning occurs during documentation generation. The process waits until all errors and warnings have been emitted first.
This setting works well with
reportUndocumented.Default:
false- suppressInheritedMembers
Whether to suppress inherited members that aren't explicitly overridden in a given class.
Note: This suppresses functions such as
equals,hashCode, andtoString, but does not suppress synthetic functions such asdataClass.componentNanddataClass.copy. UsesuppressObviousFunctionsfor that.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.Objectorjava.lang.Enum, such asequals,hashCode,toString.Synthetic (generated by the compiler) and does not have any documentation, such as
dataClass.componentNordataClass.copy.
Default:
true- offlineMode
Whether to resolve remote files and links over your network.
This includes package-lists used for generating links to external documentation.. For example, this allows to make classes from the standard library clickable in your documentation.
Setting this to
truecan significantly speed up build times in certain cases, but can also worsen user experience. For example, by not resolving class and 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 the
externalDocumentationLinkssection.Default:
false- includes
A list of Markdown files that contain subproject and package documentation. The Markdown files must match the required format.
The contents of the specified files are parsed and embedded into documentation as subproject and package descriptions.
See Dokka Gradle example for an example of what it looks like and how to use it.
Source set configuration
Dokka allows configuring some options for Kotlin source sets:
- suppress
Whether this source set should be skipped when generating documentation.
Default:
false- displayName
The display name used to refer to this source set.
The name is used both externally (for example, as the source set name visible to documentation readers) and internally (for example, for logging messages of
reportUndocumented).By default, the value is deduced from information provided by the Kotlin Gradle plugin.
- documentedVisibilities
Defines which visibility modifiers Dokka should include in the generated documentation.
Use them if you want to document
protected,internal, andprivatedeclarations, as well as if you want to excludepublicdeclarations and only document internal API.Additionally, you can use Dokka's
documentedVisibilities()function to add documented visibilities.This can be configured for each individual package.
Default:
VisibilityModifier.Public- reportUndocumented
Whether to emit warnings about visible undocumented declarations, that is declarations without KDocs after they have been filtered by
documentedVisibilitiesand other filters.This setting works well with
failOnWarning.This can be configured for each individual package.
Default:
false- skipEmptyPackages
Whether to skip packages that contain no visible declarations after various filters have been applied.
For example, if
skipDeprecatedis set totrueand your package contains only deprecated declarations, it is considered to be empty.Default:
true- skipDeprecated
Whether to document declarations annotated with
@Deprecated.This can be configured for each individual package.
Default:
false- suppressGeneratedFiles
Whether to document generated files.
Generated files are expected to be present under the
{project}/{buildDir}/generateddirectory.If set to
true, it effectively adds all files from that directory to thesuppressedFilesoption, so you can configure it manually.Default:
true- jdkVersion
The JDK version to use when generating external documentation links for Java types.
For example, if you use
java.util.UUIDin some public declaration signature, and this option is set to8, Dokka generates an external documentation link to JDK 8 Javadocs for it.Default: `8`
- languageVersion
The Kotlin language version used for setting up analysis and @sample environment.
By default, the latest language version available to Dokka's embedded compiler is used.
- apiVersion
The Kotlin API version used for setting up analysis and @sample environment.
By default, it is deduced from
languageVersion.- sourceRoots
The source code roots to be analyzed and documented. Acceptable inputs are directories and individual
.ktand.javafiles.By default, source roots are deduced from information provided by the Kotlin Gradle plugin.
- classpath
The classpath for analysis and interactive samples.
This is useful if some types that come from dependencies are not resolved or picked up automatically.
This option accepts both
.jarand.klibfiles.By default, the classpath is deduced from information provided by the Kotlin Gradle plugin.
- samples
A list of directories or files that contain sample functions which are referenced via the @sample KDoc tag.
Source link configuration
Configure source links to help readers find the source for each declaration in a remote repository. Use the dokkaSourceSets.main {} block for this configuration.
The sourceLinks {} configuration block allows you to add a source link to each signature that leads to the remoteUrl with a specific line number. The line number is configurable by setting remoteLineSuffix.
For an example, see the documentation for the count() function in kotlinx.coroutines.
The syntax of build.gradle.kts files differs from regular .kt files (such as those used for custom Gradle plugins) because Gradle's Kotlin DSL uses type-safe accessors:
- localDirectory
The path to the local source directory. The path must be relative to the root of the current project.
- remoteUrl
The URL of the source code hosting service that can be accessed by documentation readers, like GitHub, GitLab, Bitbucket, or any hosting service that provides stable URLs for source files. This URL is used to generate source code links of declarations.
- remoteLineSuffix
The suffix used to append the 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
#Land the line number is 10, the resulting URL suffix is#L10.Suffixes used by popular services:
GitHub:
#LGitLab:
#LBitbucket:
#lines-
Default:
#L
Package options
The perPackageOption configuration block allows setting some options for specific packages matched by matchingRegex:
- matchingRegex
The regular expression that is used to match the package.
Default:
.*- suppress
Whether the package should be skipped when generating documentation.
Default:
false- skipDeprecated
Whether to document declarations annotated with
@Deprecated.This can be configured on the source set level.
Default:
false- reportUndocumented
Whether to emit warnings about visible undocumented declarations, that is declarations without KDocs after they have been filtered by
documentedVisibilitiesand other filters.This setting works well with
failOnWarning.This can be configured on the source set level.
Default:
false- documentedVisibilities
Defines which visibility modifiers Dokka should include in the generated documentation.
Use them if you want to document
protected,internal, andprivatedeclarations within this package, as well as if you want to excludepublicdeclarations and only document internal API.Additionally, you can use Dokka's
documentedVisibilities()function to add documented visibilities.This can be configured on the source set level.
Default:
VisibilityModifier.Public
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 not clickable 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, you can configure external documentation links for it. This allows Dokka to generate links for types from the library, making them resolve successfully and clickable.
By default, external documentation links for Kotlin standard library, JDK, Android SDK, and AndroidX are configured.
Register external documentation links using the register() method to define each link. The externalDocumentationLinks API uses this method aligning with Gradle DSL conventions:
- url
The root URL of documentation to link to. It must contain a trailing slash.
Dokka does its best to automatically find
package-listfor the given URL, and link declarations together.If the automatic resolution fails or if you want to use locally cached files instead, consider setting the
packageListUrloption.- 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 subproject and package names.
This can also be a locally cached file to avoid network calls.
Complete configuration
Below you can see all possible configuration options applied at the same time: