Hello All, I'm implementing a binary Gradle conven...
# dokka
a
Hello All, I'm implementing a binary Gradle convention plugin to be released on Gradle Plugin Portal that would customize the look & feel of Dokka documentation for our projects. I managed to get the footer set, Android links and version, but I'd like to replace the icon and styles as well. I included the icon and css files in
/src/main/resources/dokka
in the plugin just like Dokka does with the default ones. They are successfully added to the jar file. I'm struggling with having them added to the generated documentation. Setting
customAssets
doesn't find the files, only looks inside the source code of the project for which the plugin is added to, not from the plugin itself. I tried copying them to
html/images
but again,
customAssets
is looking for them in the source, not output. I'm using Dokka 2.0.0.
The code of the plugin:
Copy code
lass NordicDokkaPlugin : Plugin<Project> {

    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("org.jetbrains.dokka")
            }

            val dokkaExtension = extensions.getByType<DokkaExtension>()
            dokkaExtension.apply {
                // Set the version.
                moduleVersion.set(getVersionNameFromTags())
                // GitHub Pages are using "docs" directory.
                basePublicationsDirectory.set(rootDir.resolve("docs"))
                // Set the footer message.
                pluginsConfiguration.named("html", DokkaHtmlPluginParameters::class.java) {
                    val year = Calendar.getInstance().get(Calendar.YEAR)
                    footerMessage.set("Copyright © 2022 - $year Nordic. All Rights Reserved.")
                }
                dokkaSourceSets.named("main") {
                   // No idea what here
                }
                // ..or here
            }
        }
    }
}
My plugin structure:
Copy code
src
  \ main
      \ kotlin
         \ NordicDokkaPlugin
      \ resources
         \ dokka
            \ images
               \ my-icon.svg
OK, maybe not perfect, but I managed to get it done with:
Copy code
class NordicDokkaPlugin : Plugin<Project> {
    private val org = "Nordic Semiconductor ASA"

    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("org.jetbrains.dokka")
            }

            val dokkaExtension = extensions.getByType<DokkaExtension>()
            dokkaExtension.apply {
                // Set the version.
                moduleVersion.set(getVersionNameFromTags())
                // Set the output directory for the documentation.
                // GitHub Pages are using "docs" directory.
                basePublicationsDirectory.set(rootDir.resolve("docs"))

                val icon = getResourceAsFile("logo-icon.svg")
                val styles = getResourceAsFile("logo-styles.css")

                // Set the footer message.
                pluginsConfiguration.named("html", DokkaHtmlPluginParameters::class.java) {
                    val year = Calendar.getInstance().get(Calendar.YEAR)
                    footerMessage.set("Copyright © 2022 - $year $org. All Rights Reserved.")
                    customAssets.from(icon.absolutePath)
                    customStyleSheets.from(styles.absolutePath)
                }
            }
        }
    }

    private fun getResourceAsFile(resourceName: String): File {
        val resource = this::class.java.getResourceAsStream("dokka/images/$resourceName")
            ?: throw IllegalStateException("Resource not found: $resourceName")
        val dir = createTempDir("dokka")
        val tempFile = File(dir, resourceName)
        dir.deleteOnExit()

        resource.use { input ->
            tempFile.outputStream().use { output ->
                input.copyTo(output)
            }
        }
        return tempFile
    }

}