Skip to content

rickclephas/kotlin-docc

Repository files navigation

Kotlin-DocC

Kotlin-DocC is a Gradle plugin that integrates the docc CLI into your Kotlin Multiplatform projects.

Generating your first .doccarchive is as easy as applying the plugin:

plugins {
    id("com.rickclephas.kmp.docc") version "0.1.0"
}

and running the doccConvert or doccPreview task for your target's framework.

Both the doccConvert and doccPreview tasks can be configured with the docC extension:

import com.rickclephas.kmp.docc.dsl.docC

group = "com.example"
version = "1.0"

kotlin {
    macosArm64 {
        binaries.framework {
            baseName = "MyFramework"
            
            docC {
                // Configure the doccConvert and doccPreview tasks
                common {
                    // Configure the fallback values for the documentation bundle's Info.plist properties
                    displayName.set("MyFramework")
                    bundleIdentifier.set("com.example.MyFramework")
                    bundleVersion.set("1.0")

                    // Use a custom Swift-DocC-Render template,
                    // by default the Kotlin-DocC-Render template is used.
                    // Setting this to `null` wil use the built-in Xcode template.
                    renderDir.set(null as Directory?)
                    
                    // Adds additional arguments to the docc command
                    additionalArgs.add("--warnings-as-errors")
                }
                
                // Configure the doccConvert task
                convert {
                    // Indicates if the `process-archive index` command should be run 
                    createIndex.set(false)
                }
                
                // Configure the doccPreview task
                preview {
                    // The port number to use for the preview web server
                    port.set(8080)
                }
            }
        }
    }
}

To further customize your documentation you can generate a .docc documentation bundle by adding files to src/commonMain/docc, or the docc folder of other source-sets.

Take a look at the official DocC documentation to learn more about formatting your documentation content and adding structure to your documentation pages.