Giter VIP home page Giter VIP logo

Comments (12)

jnizet avatar jnizet commented on June 5, 2024 24

@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
}

from dokka.

m4xp1 avatar m4xp1 commented on June 5, 2024 9

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"
}

from dokka.

autonomousapps avatar autonomousapps commented on June 5, 2024 5

For Gradle 7, I think a different approach is necessary. This is what I did:

// build.gradle.kts
plugins {
  kotlin("jvm") version "1.5.31" // or whatever
  id("org.jetbrains.dokka") version "1.5.31" // or whatever
  `maven-publish`
}

java {
  withJavadocJar()
}

// This task is added by Gradle when we use java.withJavadocJar()
val javadocJar = tasks.named<Jar>("javadocJar") {
  from(tasks.named("dokkaJavadoc"))
}

publishing {
    publications {
      create<MavenPublication>("my-library") {
        from(components["java"])
      }
    }
}

This takes advantage of Gradle's built-in wiring with java.withJavadocJar(), which is important if you want the gradle module metadata (.module file, cf pom.xml) to include information on your documentation.

from dokka.

darioseidl avatar darioseidl commented on June 5, 2024 3

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 { /*...*/ }
            }
        }
    }
}

from dokka.

ice1000 avatar ice1000 commented on June 5, 2024 2

This really helps. I think it should be added to the readme....

😅

from dokka.

mhshams avatar mhshams commented on June 5, 2024 1

Please check these thread in Kotlin discussion:
https://discuss.kotlinlang.org/t/generating-javadocs-kdocs-with-maven/839

from dokka.

dimsuz avatar dimsuz commented on June 5, 2024 1
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 :)

from dokka.

dimsuz avatar dimsuz commented on June 5, 2024

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? :)

from dokka.

dimsuz avatar dimsuz commented on June 5, 2024

@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...

from dokka.

dimsuz avatar dimsuz commented on June 5, 2024

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...

from dokka.

jnizet avatar jnizet commented on June 5, 2024
task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

from dokka.

therealbush avatar therealbush commented on June 5, 2024

For Gradle 7, I think a different approach is necessary. This is what I did:

// build.gradle.kts
plugins {
  kotlin("jvm") version "1.5.31" // or whatever
  id("org.jetbrains.dokka") version "1.5.31" // or whatever
  `maven-publish`
}

java {
  withJavadocJar()
}

// This task is added by Gradle when we use java.withJavadocJar()
val javadocJar = tasks.named<Jar>("javadocJar") {
  from(tasks.named("dokkaJavadoc"))
}

publishing {
    publications {
      create<MavenPublication>("my-library") {
        from(components["java"])
      }
    }
}

This takes advantage of Gradle's built-in wiring with java.withJavadocJar(), which is important if you want the gradle module metadata (.module file, cf pom.xml) to include information on your documentation.

This helped me out a lot. Thanks!

from dokka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.