We all know that “Good code documents itself” but documenting your code won’t hurt anyone’s(especially Vegita’s) pride.
But HOW?
To write documentation for Kotlin code we can use the following plugin:
KDoc-er – Kotlin Doc Generator – IntelliJ IDEs Plugin | Marketplace
With the plugin, we can automatically generate Kdocs like this:
/** * Image view show image from url * * @param imageUrl url of the image */
Once we are done with the Kdoc it is time to show off what we have done and we need Dokka for that.
Dokka
We have to add Dokka to our project
1- At the project level Gradle file
dependencies { classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.6.0" }
2- In each module Gradle that we want to document
apply plugin: "org.jetbrains.dokka"
Note:
Make sure that:
1- Your Gradle, android studio and project use java 11 (check by terminal with ./gradlew — version)
2- Dokka plugin must be applied after “com.android.application” and “org.jetbrains.kotlin.android”
After sync and rebuild (to make sure we can invalidate cache as well but it is optional) in terminal we will call one of the following lines:
1- ./gradlew dokkaHtml dokkaHtmlMultiModule (for multi module)
2- ./gradlew dokkaHtml dokkaHtml (for single module)
Once Dokka is done you can open index.html from the browser and well-written documentation is in front of you.
References and More
3- Dokka
With Special Thanks To
This article was originally published on proandroiddev.com on July 02, 2022