How to configure Dokka for kotlin-multiplatform

Solved: Documentation for MPP
Here’s what worked for me, based on the valuable inputs from knolle and Simon.Ogorodnik (above)…


// Do not apply the docca plugin

task docCommon(type: org.jetbrains.dokka.gradle.DokkaTask) {

outputFormat = 'javadoc'

outputDirectory = "$buildDir/doc_common"

impliedPlatforms = ["Common"] // This will force platform tags for all non-common sources e.g. "JVM"

kotlinTasks {

// dokka fails to retrieve sources from MPP-tasks so they must be set empty to avoid exception

// use sourceRoot instead (see below)

[]

}

includes = ['packages.md', 'extra.md']

sourceRoot {

// assuming there is only a single source dir...

path = kotlin.sourceSets.commonMain.kotlin.srcDirs[0]

platforms = ["Common"]

}

}//------------

task docJs(type: org.jetbrains.dokka.gradle.DokkaTask) {

outputFormat = 'javadoc'

outputDirectory = "$buildDir/doc_js"

impliedPlatforms = ["Common"] // This will force platform tags for all non-common sources e.g. "JVM"

kotlinTasks {

// dokka fails to retrieve sources from MPP-tasks so they must be set empty to avoid exception

// use sourceRoot instead (see below)

[]

}

includes = ['packages.md', 'extra.md']

sourceRoot {

// assuming there is only a single source dir...

path = kotlin.sourceSets.commonMain.kotlin.srcDirs[0]

platforms = ["Common"]

}

sourceRoot {

// assuming there is only a single source dir...

path = kotlin.sourceSets.jsMain.kotlin.srcDirs[0]

platforms = ["JS"]

}

}//--------------

task docJvm(type: org.jetbrains.dokka.gradle.DokkaTask) {

outputFormat = 'javadoc'

outputDirectory = "$buildDir/doc_jvm"

impliedPlatforms = ["Common"] // This will force platform tags for all non-common sources e.g. "JVM"

kotlinTasks {

// dokka fails to retrieve sources from MPP-tasks so they must be set empty to avoid exception

// use sourceRoot instead (see below)

[]

}

includes = ['packages.md', 'extra.md']

sourceRoot {

// assuming there is only a single source dir...

path = kotlin.sourceSets.commonMain.kotlin.srcDirs[0]

platforms = ["Common"]

}

sourceRoot {

// assuming there is only a single source dir...

path = kotlin.sourceSets.jvmMain.kotlin.srcDirs[0]

platforms = ["JVM"]

}

}//--------------

// Invoke this task to generate all three sets of documentation

task doc{

dependsOn docCommon

dependsOn docJvm

dependsOn docJs

}//----------