Andre_601
Andre_601

Reputation: 137

How to combine multiple Javadoc into one using Gradle

This question was answered before but the chosen answer doesn't explain a lot for me on how this is doable on Gradle.

That and the fact that I can't comment on the solution to ask for more info forced me to make this question.

I have a Gradle project that has several modules available and I now want to set up the Javadoc task to combine the Javadoc comments of all the modules into a single location where I could browse it.
How would I now be able to do this using Gradle? I run Gradle 5.5 if the version is of any importance and I have the following things set in the build.gradle file:

allprojects {
    ext {
        // Convenience method to configure Javadoc
        configureJavadoc = { Object jDocConfig ->
            jDocConfig.options {
                it.author()
                it.encoding = 'UTF-8'
                it.memberLevel = JavadocMemberLevel.PROTECTED

                if (it instanceof StandardJavadocDocletOptions) {
                    def opt = it as StandardJavadocDocletOptions

                    opt.links(
                            "https://docs.example.com/java/"
                    )

                    if (JavaVersion.current().isJava9Compatible()) {
                        opt.addBooleanOption("html5", true)
                        opt.addStringOption("-release", "8")
                    }

                    if (JavaVersion.current().isJava11Compatible()) {
                        opt.addBooleanOption("-no-module-directories", true)
                    }
                }
            }
        }
    }
}

subprojects {
    javadoc {
        destinationDir = file("$rootDir/docs/")
        
        configureJavadoc(it)
    }
}

Upvotes: 2

Views: 1531

Answers (2)

Flow
Flow

Reputation: 24043

You could use the io.freefair.aggregate-javadoc Gradle plugin.

Simply add the plugin to your build.grade:

plugins {
  id("io.freefair.aggregate-javadoc") version "8.10"
}

and invoke the aggregateJavadoc task:

$ gradle aggregateJavadoc

The aggregated javadoc will be in build/docs/aggregateJavadoc.

See also https://docs.freefair.io/gradle-plugins/8.10/reference/#_io_freefair_aggregate_javadoc

Upvotes: 0

Sebastian Zubrinic
Sebastian Zubrinic

Reputation: 758

I was able to do it with:

def exportedProjects = [
        ":",
        ":module-a",
        ":module-b",
        ":module-c"
]

task allJavadoc(type: Javadoc) {
    source exportedProjects.collect { project(it).sourceSets.main.allJava }
    classpath = files(exportedProjects.collect { project(it).sourceSets.main.compileClasspath })
    destinationDir = file("${buildDir}/docs/javadoc-all")
}

Upvotes: 2

Related Questions