javagradlejavadoc

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

Solution

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