I'm trying to add sample code to my API Reference.
I followed the pattern highlighted here https://androidessence.com/contributing-to-kotlin Was able to create my sample project and all the code runs, duplicating the _sampleUtils that the the kotlin stdlib source uses.
I configured my module to include the sample in the dokka configuration.
tasks.dokkaHtml {
dokkaSourceSets.configureEach {
samples.from("$projectDir/../module-samples/test/samples/SampleFile.kt")
}
}
The sample correctly loads into and is displayed in the documentation for the function with a run button.
When I hit run though, it just comes back with Unresolved reference
for all the symbols in my library. It also could not find assertPrint method from the _samplesUtils.kt file.
I don't see any other settings in the Dokka configuration for samples to make it include jar files for the library being documented.
After researching I found out that the samples are using Kotlin playground. To add extra dependencies you need to create your own compiler server. https://github.com/AlexanderPrendota/kotlin-compiler-server.
You then modify the build.gradle.kts file with your extra dependencies.
The next part is updating the html generated by Dokka to point to your new server. I couldn't find a built in way to do that, so I implemented this.
You also have to create a custom little jar to replace test code types and functions with ones that work better for samples.