Kotlin Help

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 default publications are html and javadoc.

  • The syntax of build.gradle.kts files differs from regular .kt files (such as those used for Kotlin custom plugins) because Gradle's Kotlin DSL uses type-safe accessors.

plugins { id("org.jetbrains.dokka") version "2.1.0" } dokka { dokkaPublications.html { moduleName.set(project.name) moduleVersion.set(project.version.toString()) // Standard output directory for HTML documentation outputDirectory.set(layout.buildDirectory.dir("dokka/html")) failOnWarning.set(false) suppressInheritedMembers.set(false) suppressObviousFunctions.set(true) offlineMode.set(false) includes.from("packages.md", "extra.md") // Output directory for additional files // Use this block instead of the standard when you // want to change the output directory and include extra files outputDirectory.set(rootDir.resolve("docs/api/0.x")) // Use fileTree to add multiple files includes.from( fileTree("docs") { include("**/*.md") } ) } }

For more information about working with files, see the Gradle docs.

// CustomPlugin.kt import org.gradle.api.Plugin import org.gradle.api.Project import org.jetbrains.dokka.gradle.DokkaExtension abstract class CustomPlugin : Plugin<Project> { override fun apply(project: Project) { project.plugins.apply("org.jetbrains.dokka") project.extensions.configure(DokkaExtension::class.java) { dokka -> dokka.moduleName.set(project.name) dokka.moduleVersion.set(project.version.toString()) dokka.dokkaPublications.named("html") { publication -> // Standard output directory for HTML documentation publication.outputDirectory.set(project.layout.buildDirectory.dir("dokka/html")) publication.failOnWarning.set(true) publication.suppressInheritedMembers.set(true) publication.offlineMode.set(false) publication.suppressObviousFunctions.set(true) publication.includes.from("packages.md", "extra.md") // Output directory for additional files // Use this instead of the standard block when you // want to change the output directory and include extra files html.outputDirectory.set(project.rootDir.resolve("docs/api/0.x")) } } } }
plugins { id 'org.jetbrains.dokka' version '2.1.0' } dokka { dokkaPublications { html { // Sets general module information moduleName.set(project.name) moduleVersion.set(project.version.toString()) // Standard output directory for HTML documentation outputDirectory.set(layout.buildDirectory.dir("dokka/html")) // Core Dokka options failOnWarning.set(false) suppressInheritedMembers.set(false) suppressObviousFunctions.set(true) offlineMode.set(false) includes.from(files("packages.md", "extra.md")) // Output directory for additional files // Use this block instead of the standard when you want to // change the output directory and include extra files outputDirectory.set(file("$rootDir/docs/api/0.x")) } } }
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 moduleName is 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 moduleVersion is 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 dokkaGenerate task.

Default: build/dokka/html

Output 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, and toString, but does not suppress synthetic functions such as dataClass.componentN and dataClass.copy. Use suppressObviousFunctions for 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.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

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 true can 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 externalDocumentationLinks section.

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:

import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier dokka { // .. // General configuration section // .. // Source sets configuration dokkaSourceSets { // Example: Configuration exclusive to the 'linux' source set named("linux") { dependentSourceSets{named("native")} sourceRoots.from(file("linux/src")) } configureEach { suppress.set(false) displayName.set(name) documentedVisibilities.set(setOf(VisibilityModifier.Public)) // OR documentedVisibilities(VisibilityModifier.Public) reportUndocumented.set(false) skipEmptyPackages.set(true) skipDeprecated.set(false) suppressGeneratedFiles.set(true) jdkVersion.set(8) languageVersion.set("1.7") apiVersion.set("1.7") sourceRoots.from(file("src")) classpath.from(file("libs/dependency.jar")) samples.from("samples/Basic.kt", "samples/Advanced.kt") sourceLink { // Source link section } perPackageOption { // Package options section } externalDocumentationLinks { // External documentation links section } } } }
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier dokka { // .. // General configuration section // .. dokkaSourceSets { // Example: Configuration exclusive to the 'linux' source set named("linux") { dependentSourceSets { named("native") } sourceRoots.from(file("linux/src")) } configureEach { suppress.set(false) displayName.set(name) documentedVisibilities.set([VisibilityModifier.Public] as Set) // OR documentedVisibilities(VisibilityModifier.Public) reportUndocumented.set(false) skipEmptyPackages.set(true) skipDeprecated.set(false) suppressGeneratedFiles.set(true) jdkVersion.set(8) languageVersion.set("1.7") apiVersion.set("1.7") sourceRoots.from(file("src")) classpath.from(file("libs/dependency.jar")) samples.from("samples/Basic.kt", "samples/Advanced.kt") sourceLink { // Source link section } perPackageOption { // Package options section } externalDocumentationLinks { // External documentation links section } } } }
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, and private declarations, as well as if you want to exclude public declarations 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 documentedVisibilities and 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 skipDeprecated is set to true and 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}/generated directory.

If set to true, it effectively adds all files from that directory to the suppressedFiles option, 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.UUID in some public declaration signature, and this option is set to 8, 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 .kt and .java files.

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 .jar and .klib files.

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.

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:

// build.gradle.kts dokka { dokkaSourceSets.main { sourceLink { localDirectory.set(file("src/main/kotlin")) remoteUrl("https://github.com/your-repo") remoteLineSuffix.set("#L") } } }
// CustomPlugin.kt import org.gradle.api.Plugin import org.gradle.api.Project import org.jetbrains.dokka.gradle.DokkaExtension abstract class CustomPlugin : Plugin<Project> { override fun apply(project: Project) { project.plugins.apply("org.jetbrains.dokka") project.extensions.configure(DokkaExtension::class.java) { dokka -> dokka.dokkaSourceSets.named("main") { dss -> dss.includes.from("README.md") dss.sourceLink { it.localDirectory.set(project.file("src/main/kotlin")) it.remoteUrl("https://example.com/src") it.remoteLineSuffix.set("#L") } } } } }
dokka { dokkaSourceSets { main { sourceLink { localDirectory.set(file("src/main/kotlin")) remoteUrl.set(new URI("https://github.com/your-repo")) remoteLineSuffix.set("#L") } } } }
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 #L and the line number is 10, the resulting URL suffix is #L10.

Suffixes used by popular services:

  • GitHub: #L

  • GitLab: #L

  • Bitbucket: #lines-

Default: #L

Package options

The perPackageOption configuration block allows setting some options for specific packages matched by matchingRegex:

import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier dokka { dokkaPublications.html { dokkaSourceSets.configureEach { perPackageOption { matchingRegex.set(".*api.*") suppress.set(false) skipDeprecated.set(false) reportUndocumented.set(false) documentedVisibilities.set(setOf(VisibilityModifier.Public)) // OR documentedVisibilities(VisibilityModifier.Public) } } } }
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier dokka { dokkaPublications { html { dokkaSourceSets.configureEach { perPackageOption { matchingRegex.set(".*api.*") suppress.set(false) skipDeprecated.set(false) reportUndocumented.set(false) documentedVisibilities.set([VisibilityModifier.Public] as Set) } } } } }
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 documentedVisibilities and 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, and private declarations within this package, as well as if you want to exclude public declarations 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

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:

dokka { dokkaSourceSets.configureEach { externalDocumentationLinks.register("example-docs") { url("https://example.com/docs/") packageListUrl("https://example.com/docs/package-list") } } }
dokka { dokkaSourceSets.configureEach { externalDocumentationLinks.register("example-docs") { url.set(new URI("https://example.com/docs/")) packageListUrl.set(new URI("https://example.com/docs/package-list")) } } }
url

The root URL of documentation to link to. It must contain a trailing slash.

Dokka does its best to automatically find package-list for 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 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 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:

import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier plugins { id("org.jetbrains.dokka") version "2.1.0" } dokka { dokkaPublications.html { moduleName.set(project.name) moduleVersion.set(project.version.toString()) outputDirectory.set(layout.buildDirectory.dir("dokka/html")) failOnWarning.set(false) suppressInheritedMembers.set(false) suppressObviousFunctions.set(true) offlineMode.set(false) includes.from("packages.md", "extra.md") } dokkaSourceSets { // Example: Configuration exclusive to the 'linux' source set named("linux") { dependentSourceSets{named("native")} sourceRoots.from(file("linux/src")) } configureEach { suppress.set(false) displayName.set(name) documentedVisibilities.set(setOf(VisibilityModifier.Public)) // OR documentedVisibilities(VisibilityModifier.Public) reportUndocumented.set(false) skipEmptyPackages.set(true) skipDeprecated.set(false) suppressGeneratedFiles.set(true) jdkVersion.set(8) languageVersion.set("1.7") apiVersion.set("1.7") sourceRoots.from(file("src")) classpath.from(file("libs/dependency.jar")) samples.from("samples/Basic.kt", "samples/Advanced.kt") sourceLink { localDirectory.set(file("src/main/kotlin")) remoteUrl("https://example.com/src") remoteLineSuffix.set("#L") } externalDocumentationLinks { url = URL("https://example.com/docs/") packageListUrl = File("/path/to/package-list").toURI().toURL() } perPackageOption { matchingRegex.set(".*api.*") suppress.set(false) skipDeprecated.set(false) reportUndocumented.set(false) documentedVisibilities.set( setOf( VisibilityModifier.Public, VisibilityModifier.Private, VisibilityModifier.Protected, VisibilityModifier.Internal, VisibilityModifier.Package ) ) } } } }
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier plugins { id 'org.jetbrains.dokka' version '2.1.0' } dokka { dokkaPublications { html { moduleName.set(project.name) moduleVersion.set(project.version.toString()) outputDirectory.set(layout.buildDirectory.dir("dokka/html")) failOnWarning.set(false) suppressInheritedMembers.set(false) suppressObviousFunctions.set(true) offlineMode.set(false) includes.from("packages.md", "extra.md") } } dokkaSourceSets { // Example: Configuration exclusive to the 'linux' source set named("linux") { dependentSourceSets { named("native") } sourceRoots.from(file("linux/src")) } configureEach { suppress.set(false) displayName.set(name) documentedVisibilities.set([VisibilityModifier.Public] as Set) reportUndocumented.set(false) skipEmptyPackages.set(true) skipDeprecated.set(false) suppressGeneratedFiles.set(true) jdkVersion.set(8) languageVersion.set("1.7") apiVersion.set("1.7") sourceRoots.from(file("src")) classpath.from(file("libs/dependency.jar")) samples.from("samples/Basic.kt", "samples/Advanced.kt") sourceLink { localDirectory.set(file("src/main/kotlin")) remoteUrl.set(new URI("https://example.com/src")) remoteLineSuffix.set("#L") } externalDocumentationLinks { url.set(new URI("https://example.com/docs/")) packageListUrl.set(new File("/path/to/package-list").toURI().toURL()) } perPackageOption { matchingRegex.set(".*api.*") suppress.set(false) skipDeprecated.set(false) reportUndocumented.set(false) documentedVisibilities.set([ VisibilityModifier.Public, VisibilityModifier.Private, VisibilityModifier.Protected, VisibilityModifier.Internal, VisibilityModifier.Package ] as Set) } } } }
18 December 2025