Trouble getting started with dokka and Gradle

My build.gradle.kts is pretty simple:

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.3.70"
    id("org.jetbrains.dokka") version "0.10.1"
}

repositories {
    jcenter()
}

dependencies {
    implementation(kotlin("stdlib"))
    testImplementation("junit:junit:4.12")
}

With Gradle 6.2.2, I can e.g. run gradle test:

~/projects/ktlib  $ gradle -version

------------------------------------------------------------
Gradle 6.2.2
------------------------------------------------------------

Build time:   2020-03-04 08:49:31 UTC
Revision:     7d0bf6dcb46c143bcc3b7a0fa40a8e5ca28e5856

Kotlin:       1.3.61
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_202 (Oracle Corporation 25.202-b08)
OS:           Linux 4.15.0-88-generic amd64

~/projects/ktlib  $ gradle test

BUILD SUCCESSFUL in 730ms
~/projects/ktlib  $ 

And I can run dokka too:

~/projects/ktlib  $ gradle dokka

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 11s
1 actionable task: 1 executed

However, if I add to build.gradle.kts the configuration recommended in the documentation:

tasks {
    val dokka by getting(DokkaTask::class) {
        outputFormat = "html"
        outputDirectory = "$buildDir/dokka"
    }
}

Gradle isn’t happy:

~/projects/ktlib  $ gradle test

> Configure project :
e: /home/vinay/projects/ktlib/build.gradle.kts:16:26: Unresolved reference: DokkaTask
e: /home/vinay/projects/ktlib/build.gradle.kts:17:9: Unresolved reference: outputFormat
e: /home/vinay/projects/ktlib/build.gradle.kts:18:9: Unresolved reference: outputDirectory

FAILURE: Build failed with an exception.

* Where:
Build file '/home/vinay/projects/ktlib/build.gradle.kts' line: 16

* What went wrong:
Script compilation errors:

  Line 16:     val dokka by getting(DokkaTask::class) {
                                    ^ Unresolved reference: DokkaTask

  Line 17:         outputFormat = "html"
                   ^ Unresolved reference: outputFormat

  Line 18:         outputDirectory = "$buildDir/dokka"
                   ^ Unresolved reference: outputDirectory

3 errors

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 870ms

What needs to be done to fix this?

Use the fully qualified name org.jetbrains.dokka.gradle.DokkaTask::class or add an import statement import org.jetbrains.dokka.gradle.DokkaTask to the build.gradle.kts file.

1 Like

Thanks, that worked. Might be obvious to someone experienced with the DSL, but not to this newbie :frowning: One certainly couldn’t divine the fully-qualified name without resorting to a search for it.

It might be useful to add that to the README where that “minimal dokka configuration” is mentioned, so I created a PR to add it.

1 Like

Great, thank you!