Hi friends! With the release of dokka 2.1.0, I nee...
# dokka
p
Hi friends! With the release of dokka 2.1.0, I need to catch up and update our projects, so I beseech your wisdom. πŸ˜… See thread. 🧡
I used to have this piece of code to generate
javadoc.jar
for our libraries:
Copy code
named<DokkaTask>("dokkaHtml").let { documentation ->
    documentation.configure {
        dokkaSourceSets.configureEach {
            // configuration here ...
            sourceLink {
                // ...
            }
        }
    }

    register<Jar>("javadocJar") {
        dependsOn(documentation)
        archiveClassifier.set("javadoc")
        from(documentation.flatMap { it.outputDirectory })
    }
}
And then, at some point:
Copy code
publishing {
    publications {
        withType<MavenPublication> {
            artifact(tasks.named("javadocJar"))
            ...
        }
    }
}
I managed to configure our code to dokka 2.1.0, but the part of generating the
javadoc.jar
artifact was missing. I checked the documentation and the suggested code didn't work (not sure if it was updated), so any suggestions are welcome. πŸ˜‰
I might need a solution that could work for multimodule projects, KMP and also JVM-only. (ok, I will stop now πŸ˜…_)_
I tried this:
Copy code
register<Jar>("javadocJar") {
    named<DokkaGeneratePublicationTask>("dokkaGeneratePublicationJavadoc").let { documentation ->
        dependsOn(documentation)
        from(documentation.flatMap { it.outputDirectory })
    }
    archiveClassifier.set("javadoc")
}
And it seems to work, but I am not sure this is the official way... πŸ˜…
o
Hey! Our documentation is currently being updated for DGPv2. But at this moment, there is some explanation on how to do it in the issue here. Also, we do have an example project. So yes, this is kind of an official way πŸ™‚ Question while we are here: What is the reason you are using the Javadoc output format?
gratitude thank you 1
πŸ”₯ 1
p
Hi @Oleg Yukhnevich! Thank you so much for confirming it! Dokka is amazing! πŸŽ‰ We use the Javadoc format in our
publish
task to have our
library>-javadoc.jar
built as well (the default behaviour only generates the library binary itself and sources, but not documentation).
o
Is there a reason you need for Dokka to generate documentation in javadoc format, and not in our own HTML format, which works nicer and shows real Kotlin declarations, like here:https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/ ?
πŸ‘€ 1
p
@Oleg Yukhnevich Ah I see! I think old habits die hard. 😁 I will discuss with the team so we can move to the HTML format.
thank you color 1
a
hey πŸ‘‹ Some Gradle nitpicking: your code should work, but if you're using Dokka 2.1.0 it can be simplified
Copy code
register<Jar>("javadocJar") {
    val dokkaGeneratePublicationJavadoc = named<DokkaGeneratePublicationTask>("dokkaGeneratePublicationJavadoc")
    from(dokkaGeneratePublicationJavadoc)
    archiveClassifier.set("javadoc")
}
Gradle will automatically use the output of the
dokkaGeneratePublicationJavadoc
task, and automatically infer the task dependencies. I'll update the example to remove the unnecessary
.flatMap { it.outputDirectory }
...
gratitude thank you 1
πŸ”₯ 1
p
That's brilliant, thanks @Adam Semenenko! gratitude thank you