Dokka生成HTML中KDoc注解未渲染问题求助
Hey there! Let's work through these Dokka documentation issues step by step—your code is on the right track, most of these quirks come from outdated tooling or small KDoc syntax missteps.
Key First Step: Upgrade Your Dokka & Kotlin Versions
You're using Dokka 0.9.15 and Kotlin 1.2.0, both of which are extremely outdated (released in 2017!). Many of the tag and rendering issues you're seeing were fixed in newer versions. Let's update your top-level build.gradle first:
buildscript { ext.kotlin_version = '1.8.22' // Use latest stable Kotlin version ext.dokka_version = '1.8.22' // Match Dokka version to Kotlin for best compatibility repositories { google() mavenCentral() // jcenter is deprecated, switch to mavenCentral } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // Update Android Gradle Plugin too classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}" } }
And update your module-level build.gradle Dokka configuration to match the newer syntax:
// Replace the old dokka block with this dokkaHtml { outputDirectory.set(file("$buildDir/html")) }
Fixing Individual Issues
1. Class-level @sample & HTML Tags Not Rendering
Outdated Dokka had poor support for inline HTML tags in KDoc. Instead of using <h1> or <p>, use Markdown syntax (which Dokka fully supports) for better compatibility:
/** * # A Simple Calculator for your daily needs! * * This class can help you add, subtract, multiply and divide Integers * * @property firstNumber the first Number you want to use * @property secondNumber the second Number you want to use. * @constructor Creates a Simple Calculator with the two numbers * @sample example.SimpleCalculator(100,10) // Add full qualified name to ensure Dokka finds the sample */ class SimpleCalculator(val firstNumber: Int, val secondNumber: Int) { ... }
The updated Dokka version will render the Markdown heading and paragraphs correctly, and the fully qualified @sample path ensures the example is picked up.
2. Enum Class Nested HTML Content Not Showing
Same root cause: old Dokka struggled with HTML in enum KDoc. Switch to Markdown here too, and the content will render properly:
/** * # An OPERATOR checker to be used by the Simple Calculator * * This enum has four values: * - ADD * - SUB * - MUL * - DIV * @see SimpleCalculator */ enum class OPERATOR { ADD, SUB, MUL, DIV }
3. Method-level @sample & @property Tags Not Displaying
- @property in methods is invalid: This tag is only meant for class properties. For method parameters, use
@paraminstead (you already did this correctly in some methods—fix the ones that use@property). - @sample not showing: Again, use fully qualified names for your samples, and the updated Dokka will render them. For example:
/** * Adds the [firstNumber] and [secondNumber] you have created with [SimpleCalculator]. * @param firstNumber the first number * @param secondNumber the second number * @sample example.SimpleCalculator.add(100, 10) * @see SimpleCalculator * @return the sum */ fun add(firstNumber: Int, secondNumber: Int): Int = firstNumber + secondNumber
4. @param Confusion Between Classes & Methods
This is actually expected behavior per KDoc standards:
- For class generic parameters (like
Group<T>),@param <T>refers to the type parameter inside the angle brackets. - For method parameters,
@param parameterNamerefers to the value parameters in the method's parameter list.
This is not a Dokka bug—it's how KDoc is designed to distinguish between different types of parameters.
Final Checks
After updating versions and fixing KDoc syntax, run ./gradlew dokkaHtml to regenerate your documentation. All your tags, samples, and text should render correctly now.
内容的提问来源于stack exchange,提问作者Paula Kristin




