This article is about fixing Exception lateinit property module has not been initialized in Kotlin Dokka
  • 01-Feb-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing Exception lateinit property module has not been initialized in Kotlin Dokka

Exception: lateinit property module has not been initialized in Kotlin Dokka

Lightrun Team
Lightrun Team
01-Feb-2023

Explanation of the problem

The task dokkaHtml of the module vfg-foundation has failed during the execution of the gradle build process on the Android platform. The exception message is lateinit property module has not been initialized. The build process is only successful when run with the debug build type. To gain more insights, try running the build process with the options --info or --debug or with --scan for full information. The full stack trace of the exception is as follows:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':vfg-foundation:dokkaHtml'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:207)
	...
	...

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for Exception: lateinit property module has not been initialized in Kotlin Dokka

The issue that the author is facing is with the Dokka JavaDoc tool not properly generating documentation for the source code of their Android project. In order to resolve this issue, the author has made changes to their build.gradle file.

The original code in the build.gradle file contained the following:

outputDirectory.set(file("$buildDir/../../../../docs/java-docs"))
dokkaSourceSets {
    configureEach {
        includeNonPublic.set(false)
        skipDeprecated.set(false)
        reportUndocumented.set(false)
        skipEmptyPackages.set(true)
        sourceRoots.setFrom(file("$buildDir/../../../../src/android/java"))
    }
}

The author noticed that the configureEach function was not properly generating documentation for their source code. In order to resolve this issue, they made the following change to their code:

dokkaJavadoc.configure {
    outputDirectory.set(file("$buildDir/../../../../docs/java-docs"))
    dokkaSourceSets {
        main {
            includeNonPublic.set(false)
            skipDeprecated.set(false)
            reportUndocumented.set(false)
            skipEmptyPackages.set(true)
            sourceRoots.setFrom(file("$buildDir/../../../../src/android/java"))
        }
    }
}

By replacing the configureEach function with the main function, the author was able to successfully generate the desired documentation for their source code. This change allowed for proper configuration of the Dokka JavaDoc tool, resulting in the generation of accurate and complete documentation.

Other popular problems with Dokka

Problem: Incorrect Source Root Configuration

One common issue with Kotlin Dokka is incorrect source root configuration. When the source roots are not set correctly, the generated documentation may not reflect the actual code structure and contents.

Solution:

This can be solved by properly specifying the source roots in the build.gradle file. Here is an example of how to set the source roots in the build.gradle file:

dokkaJavadoc.configure {
    sourceRoots.setFrom(file("$projectDir/src/main/kotlin"))
}

Problem: Missing Non-Public Members in Documentation

Another common issue is the missing documentation for non-public members in the generated documentation. This is because the includeNonPublic property is set to false by default.

Solution:

To include the documentation for non-public members in the generated documentation, set the includeNonPublic property to true in the build.gradle file, like so:

dokkaJavadoc.configure {
    includeNonPublic.set(true)
}

Problem: Deprecated Members Not Skipped

The skipDeprecated property is set to false by default, which means that deprecated members are included in the generated documentation. This can result in cluttered documentation that is difficult to navigate.

Solution:

To skip the documentation for deprecated members, set the skipDeprecated property to true in the build.gradle file, like so:

dokkaJavadoc.configure {
    skipDeprecated.set(true)
}

A brief introduction to Dokka

Kotlin Dokka is a documentation engine for generating high-quality documentation for Kotlin projects. It provides a flexible and customizable platform for documenting code and generating reports in HTML, Markdown, and other popular formats. The tool is designed to be integrated with the Kotlin ecosystem, making it simple to integrate with other Kotlin tools and services.

Kotlin Dokka uses the Abstract Syntax Tree (AST) of Kotlin source code to extract information and generate API documentation. This information includes information about classes, functions, properties, and other elements of the code. The tool is also capable of handling multiple source sets, including those for libraries and multiple modules within a project. The generated documentation can be customized using Dokka’s template engine, which provides the ability to control the output format and presentation of the API documentation. Additionally, Kotlin Dokka can automatically detect and include information about dependencies and links to source code, making it easier to navigate and understand the API documentation.

Most popular use cases for Dokka

  1. Kotlin Dokka is a documentation engine for Kotlin projects that can be used to generate accurate, customizable and readable documentation for your codebase. It supports various output formats such as HTML, Markdown and JavaDoc.
  2. Dokka can be utilized for various purposes, including but not limited to:
    • Providing clear and concise information about the project structure, classes, methods, and functions
    • Improving the overall code quality by making it easier to understand, maintain and extend
    • Making it easier for other developers to understand and use the codebase, particularly for projects with multiple contributors or for open-source projects where a good documentation is crucial for wider adoption.
  3. Dokka provides a way to document the code using JavaDoc style comments in your code. For example:
/**
 * This is an example of how to document a function using Kotlin Dokka.
 * 
 * @param input The input parameter.
 * @return The output.
 */
fun exampleFunction(input: String): String {
    return input.toUpperCase()
}

By documenting the code using JavaDoc style comments, the documentation will be automatically generated in a readable format.

Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By clicking Submit I agree to Lightrun’s Terms of Use.
Processing will be done in accordance to Lightrun’s Privacy Policy.