You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kdoc生成问题求助:类缺失、样式优化及伴生对象不显示

Fixing Your Dokka Documentation Issues

Hey there! Let's work through these three Dokka problems you're facing—they're all solvable with a few tweaks to your Gradle config. Here's what to do:

1. Missing Classes in Generated Docs

It’s likely Dokka’s default settings are excluding some classes, or you haven’t configured it to scan all your source code. Try these fixes:

  • Include non-public classes: If your missing classes are marked internal, Dokka hides them by default. Add this to your module’s Dokka config to show them:
    dokkaHtml {
        includeNonPublic.set(true)
        // If you only want internal (not private) classes, use this instead:
        // includeNonPublic.set(false)
        // nonPublicMarkers.set(setOf("kotlin.internal"))
    }
    
  • Ensure all source sets are scanned: Double-check that Dokka is looking at your main source directory. For multi-module projects, make sure you’ve enabled child module inclusion in the root config:
    dokkaHtmlMultiModule {
        includeChildModules.set(true)
    }
    
  • Check for excluded files: If you’ve manually excluded any files from your Gradle source sets, they won’t show up in Dokka. Verify your sourceSets block doesn’t have unexpected exclusions.

2. Getting the Clean, Modern Dokka Style

The tutorial you followed uses an older Dokka version—today’s Dokka has a much nicer default HTML theme, but you need to make sure you’re on the latest plugin version first:

  1. Upgrade Dokka: Update the plugin version in your root settings.gradle.kts (or settings.gradle for Groovy):
    plugins {
        id("org.jetbrains.dokka") version "1.9.10" apply false
    }
    
  2. Tweak theme settings (optional): If you want to customize the look further, you can add custom CSS or adjust theme parameters:
    dokkaHtml {
        // Add a custom footer message
        footerMessage.set("Generated with Dokka | © 2024 Your Project")
        // Use a custom stylesheet (place your CSS in src/main/resources)
        customStyleSheets.from(files("src/main/resources/dokka-custom.css"))
    }
    
    The latest Dokka HTML output should match the polished look from the tutorial (and better!) once you’re on the newest version.

3. Showing Companion Objects in Docs

Companion objects are hidden by default in Dokka—you just need to enable them explicitly in your config:

dokkaHtml {
    includeCompanionObjects.set(true)
}

If your companion object’s members are internal or private, don’t forget to enable includeNonPublic as well (like in the first fix) to make those visible too. Also, ensure the companion object itself isn’t marked private—only public/internal companions will show up even with the setting enabled.

Hope these tweaks get your Dokka docs looking complete and styled just how you want! If you hit any roadblocks with the configs, feel free to share a snippet of your build file and I can help refine it further.

内容的提问来源于stack exchange,提问作者XCarb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 10:07:57