https://kotlinlang.org logo
#dokka
Title
# dokka
s

solonovamax

11/21/2023, 1:01 AM
Hi, what is the recommended way to publish javadocs for dokka? Currently, I am doing the following in an MPP project:
Copy code
tasks {
    val dokkaHtml by named<DokkaTask>("dokkaHtml")

    val javadocJar by register<Jar>("javadocJar") {
        dependsOn(dokkaHtml)
        from(dokkaHtml.outputDirectory)
        archiveClassifier = "javadoc"
        group = JavaBasePlugin.DOCUMENTATION_GROUP
    }

    publishing.publications.withType<MavenPublication>().configureEach {
        artifact(javadocJar)
    }
}
and in a non-MPP project, the publishing part is switched out for what applies to that. Publishing the javadocs in this way does produce a
-javadoc
jar, however, looking at the
.module
file that gradle produces, it does not list the javadoc. (both MPP and kotlin/jvm) If you make a standard java project with
Copy code
java {
    withSourcesJar()
    withJavadocJar()
}
then, it will produce a
.module
file which contains the following:
Copy code
{
  "formatVersion": "1.1",
  "component": {
    "group": "test-groupid",
    "module": "lib",
    "version": "1.2.3",
    "attributes": {
      "org.gradle.status": "release"
    }
  },
  "createdBy": {
    "gradle": {
      "version": "8.4"
    }
  },
  "variants": [
    // [...]
      {
      "name": "javadocElements",
      "attributes": {
        "org.gradle.category": "documentation",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.docstype": "javadoc",
        "org.gradle.usage": "java-runtime"
      },
      "files": [
        {
          "name": "lib-1.2.3-javadoc.jar",
          "url": "lib-1.2.3-javadoc.jar",
          "size": 80337,
          "sha512": "1c2d1f68d8eebbca6fc926227bb2e8df1f9ea2dda5723178492027b10533f9b89179ce59038ae219df740ddfe88792a23e07c320b76d5ed168ce816c891e5840",
          "sha256": "a9f21d3ae2a54d1c7336a13fd9468af35d270a183aaabc377ff08692320b0633",
          "sha1": "8057ffdedfffb8bef9757c7ccbbeac367dfd1025",
          "md5": "adad08c12523570066086bf8987483eb"
        }
      ]
    }
  ]
}
Is there any way to get this same behaviour with dokka?
a

Adam S

11/29/2023, 6:21 AM
I've had a dig through some of my KMP libraries that I've published to Maven Central (which requires a Javadoc JAR) without using Dokka, and I can't see the javadocElements variant for any of them. I think this is a Gradle or Kotlin Gradle Plugin issue - I'd try asking in #gradle. My guess is that the Javadoc JAR really isn't used for anything in the Kotlin world - the sources JAR is more important, and that's present by default.
c

CLOVIS

11/29/2023, 8:50 AM
@Adam S do you have an example visible on javadoc.io with the dokka output + the build.gradle.kts file that generated it? I guess if it shows up on javadoc.io, then it's not really relevant whether or not it appears in the Gradle metadata file
a

Adam S

11/29/2023, 8:57 AM
Oh, I'd never heard of that site before! It looks like MockK works, and that's a KMP project https://javadoc.io/doc/io.mockk/mockk/latest/index.html the Javadoc JAR uses the Dokka HTML output: https://github.com/mockk/mockk/blob/fa0fb5a8dea1681c301e6e16421443051c8a139f/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-multiplatform.gradle.kts#L31-L34 I bet it's not using the Gradle metadata though, probably just the Maven data
1
c

CLOVIS

11/29/2023, 8:59 AM
I bet it's not using the Gradle metadata though, probably just the Maven data
Probably. I can't speak for OP, but personally, as long as all the MavenCentral-based tools can find the documentation, and IDEA can find it too (even if it's from the sources JAR), I don't really mind what's in the metadata
s

solonovamax

12/02/2023, 9:45 PM
I know that the javadoc can be found, however I would like if the gradle module metadata could also be published as well.
4 Views