Harri
Harri

Reputation: 838

How can I generate Javadoc for my Android library with Dokka for both the main and the androidTest source sets?

I am slowly moving my library project from Java to Kotlin. I have a requirement that I also need to provide Javadoc for both the library and the Android instrumentation tests in has. I can't use Javadoc anymore as it dies when it sees a *.kt file. So I turned to Dokka.

My issue is that I can easily generate Javadoc with Dokka, but only for the main source set. But I can't get it to generate docus for my instrumentation tests.

I have the following configuration in the library build gradle:

apply plugin: 'org.jetbrains.dokka'
...
dokkaJavadoc.configure {
    dokkaSourceSets {
        named("main") {
            // Main source set conf
            outputDirectory = file("dokkadoc/service-doc")
            includes.from(files("dokka_modules_test.md"))
            sourceRoots.from(file("src/main/java"))
        }
        named("androidTest") {
            // Test source set conf
            outputDirectory = file("dokkadoc/service-test-doc")
            includes.from(files("dokka_modules_test.md"))
            sourceRoots.from(file("src/androidTest/java"))
        }
        configureEach {
            // Shared conf for all source sets
            noAndroidSdkLink.set(false)
            includeNonPublic.set(false)
            skipEmptyPackages.set(true)
            reportUndocumented.set(true)
            skipDeprecated.set(false)
        }

    }
}

In the root build.grade I import:

buildscript {
    ..
    ext.dokka_version = '1.4.10.2'
    repositories {
        ..
    }
    dependencies {
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
    }
}

What am I doing wrong? Or did I misunderstood and I can't generate sepatate Javadocs this way? Do I have to generate extension tasks for all build variants, a la:

libraryVariants.all { variant ->

..

def variantDokkadoc = task("dokkadoc${variant.name.capitalize()}", type: org.jetbrains.dokka.gradle.DokkaTask) {
...
}

EDIT: Seems when I create a separate task for the tests part like this then it does it:

// Dokka task for Service tests
task dokkaJavadocTests(type: org.jetbrains.dokka.gradle.DokkaTask) {
    dokkaSourceSets {
        named("main") {
            outputDirectory.set(file("dokkadoc/service-test-doc"))
            includes.from(files("dokka_modules_test.md"))
            sourceRoots.setFrom(file("src/main/java"))
            sourceRoots.from(file("src/androidTest/java"))

            noAndroidSdkLink.set(false)
            includeNonPublic.set(false)
            skipEmptyPackages.set(true)
            reportUndocumented.set(true)
            skipDeprecated.set(false)
        }
    }
}

For some reason, I have to go with

named("main")

otherwise it ignores the test classes.

Also, I am still unable to generate the Javadoc version, it generates the HTML one. If I add

outputFormat = "javadoc"

then it just ignores it

EDIT 2:

For now, I solved this by making a second task for tests and keeping both of them in HTML format. Eg:

// Main dokka task for the library
dokkaHtml.configure {
    dokkaSourceSets {
        named("main") {
            // Main source set conf
            outputDirectory.set(file("dokkadoc/${project.ext.versionNameDokkaDoc}"))
            includes.from(files("dokka_modules_main.md"))

            noAndroidSdkLink.set(false)
            includeNonPublic.set(false)
            skipEmptyPackages.set(true)
            reportUndocumented.set(true)
            skipDeprecated.set(false)
        }
    }
}

// Dokka task for the library tests
task dokkaHtmlTests(type: org.jetbrains.dokka.gradle.DokkaTask) {
    dokkaSourceSets {
        named("main") {
            outputDirectory.set(file("dokkadoc/${project.ext.versionNameDokkaDocTests}"))
            includes.from(files("dokka_modules_test.md"))
            sourceRoots.setFrom(file("src/main/java"))
            sourceRoots.from(file("src/androidTest/java"))

            noAndroidSdkLink.set(false)
            includeNonPublic.set(false)
            skipEmptyPackages.set(true)
            reportUndocumented.set(true)
            skipDeprecated.set(false)
        }
    }
}

Upvotes: 8

Views: 1858

Answers (0)

Related Questions