AleksanderNowakowski
12/19/2024, 8:47 PM/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.AleksanderNowakowski
12/19/2024, 8:54 PMlass 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
}
}
}
}
AleksanderNowakowski
12/19/2024, 8:57 PMsrc
\ main
\ kotlin
\ NordicDokkaPlugin
\ resources
\ dokka
\ images
\ my-icon.svg
AleksanderNowakowski
12/20/2024, 2:11 PMclass 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
}
}