just like javadoc maven plugin, dokka plugin should be able to build a jar file containing the kdocs.
This is, in particular, useful when the docs are needed to be published to a repository (maven central for example)
Please check these thread in Kotlin discussion:
https://discuss.kotlinlang.org/t/generating-javadocs-kdocs-with-maven/839
How would I go about generating a javadoc jar with the gradle plugin?
I have an android library written in kotlin and I'd like to have a javadoc.jar accompanying it.
I understand only a maven plugin supports this as of now? What are my options? :)
@dimsuz Here's an example:
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = javadoc.destinationDir
inputs.dir 'src/main/kotlin'
}
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
@jnizet Thank you!
Do you know by chance how one could also generate a sources.jar using gradle task? I understand that this might not be dokka related, but so far I didn't find any example anywhere on how to do that (specifically for an android project)...
I need this because IntelliJ seems to take documentation only from sources.jar: I even tried providing it a custom path to javadoc.jar, but it doesn't do anything, in a project using my library its methods still look undocumented...
I'm talking here about a kotlin-based library which should have .kt sources inside sources.jar. kotlin's stdlib has it and it works, but I understand it uses maven for that...
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
A problem occurred evaluating project ':app'.
> Could not find property 'main' on SourceSet container.
It seems things are not so easy for android stuff. Ok, so that still leaves me in an 'investigation is pending' state :)
This really helps. I think it should be added to the readme....
:sweat_smile:
For me it was not obvious, who can come in handy. In order to generate javadoc.jar with dokka for android, write the following:
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
classifier = 'javadoc'
from "$buildDir/javadoc"
}
Thanks y'all. In a multi-module project with Kotlin DSL, it worked for me like this to publish with Javadoc JAR to Maven:
subprojects {
//...
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "maven-publish")
//...
tasks {
val sourcesJar by registering(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val javadocJar by registering(Jar::class) {
dependsOn("dokkaJavadoc")
archiveClassifier.set("javadoc")
from(javadoc)
}
artifacts {
archives(sourcesJar)
archives(javadocJar)
archives(jar)
}
}
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["javadocJar"])
pom { /*...*/ }
}
}
}
}
Most helpful comment
@dimsuz Here's an example: