Skip to content
rife2Public

About

bld Extension to Generate API Documentation with Dokka for Kotlin

Topics

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

156 Commits

Folders and files

Repository files navigation

bld Extension to Generate API Documentation with Dokka for Kotlin

License Java bld Release Snapshot GitHub CI

To install the latest version, add the following to the lib/bld/bld-wrapper.properties file:

bld.extension-dokka=com.uwyn.rife2:bld-dokka

For more information, please refer to the extensions documentation.

Generate API Documentation

To generate a project's documentation in various formats. The examples below use fromProject, loggingLevel, outputDir, outputFormat, failOnWarning, and execute:

import java.io.File;

import rife.bld.extension.DokkaOperation;
import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat;
import rife.bld.extension.tools.IOTools;

...

@BuildCommand(value = "dokka-gfm", summary = "Generates documentation in GitHub flavored markdown format")
public void dokkaGfm() throws ExitStatusException, IOException, InterruptedException {
    new DokkaOperation()
            .fromProject(this)
            .loggingLevel(LoggingLevel.INFO)
            // Create build/dokka/gfm
            .outputDir(IOTools.resolveFile(buildDirectory(), "dokka", "gfm"))
            .outputFormat(OutputFormat.MARKDOWN) // required
            .execute();
}

@BuildCommand(value = "dokka-html", summary = "Generates documentation in HTML format")
public void dokkaHtml() throws ExitStatusException, IOException, InterruptedException {
    new DokkaOperation()
            .fromProject(this) // required
            .loggingLevel(LoggingLevel.INFO)
            // Create build/dokka/html
            .outputDir(IOTools.resolveFile(buildDirectory(), "dokka", "html"))
            .outputFormat(OutputFormat.HTML) // required
            .execute();
}

@BuildCommand(value = "dokka-jekyll", summary = "Generates documentation in Jekyll flavored markdown format")
public void dokkaJekyll() throws ExitStatusException, IOException, InterruptedException {
    new DokkaOperation()
            .fromProject(this) // required
            .loggingLevel(LoggingLevel.INFO)
            // Create build/dokka/jekyll
            .outputDir(IOTools.resolveFile(buildDirectory(), "dokka", "jekyll"))
            .outputFormat(OutputFormat.JEKYLL) // required
            .execute();
}

@BuildCommand(summary = "Generates Javadoc for the project")
@Override
public void javadoc() throws ExitStatusException, IOException, InterruptedException {
    new DokkaOperation()
            .fromProject(this) // required
            .failOnWarning(true)
            .loggingLevel(LoggingLevel.INFO)
            // Create build/javadoc
            .outputDir(new File(buildDirectory(), "javadoc"))
            .outputFormat(OutputFormat.JAVADOC) // required
            .execute();
}
./bld javadoc
./bld dokka-html
./bld dokka-gfm
./bld dokka-jekyll

Configuring Source Sets

fromProject seeds the source set with src/main/kotlin, plus the project's compile and provided classpath jars, the project's javaRelease (as the source set's JDK version), and the project name as the module name. Projects with sources elsewhere — for example mixed Java/Kotlin, generated sources, or extra source roots — must extend the source set themselves.

Call fromProject first so the defaults and classpath are populated, then add sources with sourceSet(Consumer<SourceSet):

new DokkaOperation()
        .fromProject(this) // seeds src/main/kotlin, classpath, jdkVersion, moduleName
        .sourceSet(ss -> ss
        .src(new File("src/main/java"))      // mixed Java/Kotlin
        .src(new File("src/generated/kotlin")))
        .outputFormat(OutputFormat.JAVADOC)
        .outputDir(new File(buildDirectory(), "javadoc"))
        .execute();

For a fully custom source set (no src/main/kotlin, no project classpath), pass a configured SourceSet to sourceSet(SourceSet) before calling fromProject — fromProject only adds defaults when the source set is empty, so anything you set first is preserved.

Setting the Dokka Version

By default, the extension downloads the version defined by the DOKKA_VERSION constant.

You can override this to target a specific Dokka release with the version(String) method (or version(Version)):

new DokkaOperation()
        .fromProject(this)
        .version("2.1.0") // String form
//      .version(new VersionNumber(2, 1, 0)) // Version form
        .loggingLevel(LoggingLevel.INFO)
        .outputDir(new File(buildDirectory(), "javadoc"))
        .outputFormat(OutputFormat.JAVADOC)
        .execute();

Warning: Only Dokka 2.x releases are supported.

Other Options

The following are commonly used but not shown in the main examples; see the API Reference for the full list.

Template Project

There is also a Kotlin Template Project with support for Dokka and the Detekt extensions.

API Reference

Please check the Dokka Operation documentation for all available configuration options.

About

bld Extension to Generate API Documentation with Dokka for Kotlin

Topics

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages