kotlingradle-kotlin-dsldocumentation-generationkotlin-dokka

Dokka is not generating documentation for test package


I have KDoc style comments in my tests code and I want to generate documentation using Kotlin DSL Gradle dokkaHtml tasks. But after successfully executing the task it says "Exiting Generation: Nothing to document".

I have tried to set sources but nothing has changed. I want to get the html documentation for code in my test package.


Solution

  • Dokka is meant to be used to document source code of libraries, to provide documentation to publish about how your API works. The test source set is supposed to contain unit tests for testing the library code, and not neccesarily to also document the library; that's the job of the library itself, the main source set. Sample functions (https://kotlinlang.org/docs/kotlin-doc.html#sample-identifier) would generate documentation, though. Alternatively, you can configure dokka to consider the test source set as source code, and not testing code:

    tasks.withType<DokkaTask>().configureEach {
        dokkaSourceSets {
            named("test") {
                sourceRoots.from(file("src/test/"))
            }
        }
    }
    

    See also: https://kotlinlang.org/docs/dokka-gradle.html#source-set-configuration