How generate javadoc with Gradle?

混江龙づ霸主 提交于 2020-02-26 12:25:06

问题


I would like generate javadoc out of aar lib file, but my actual task not work and finish with error. I'm somewhat lost with gradle.

Where should generate javadocs?

android.libraryVariants.all { variant ->

    // This part is for change AAR location
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.aar')) {
            def fileName = "${archivesBaseName}-${version}.aar"
            output.outputFile = new File("$rootProject.projectDir/build/generated-aar", fileName)
        }
    }

    // Here generate tasks for variant to generate Javadocs
    task "generate${variant.name.capitalize()}Javadoc"(type: Javadoc) {
        description = "Generates javadoc for build $variant.name"
        destinationDir = new File("$rootProject.projectDir/build/generated-javadoc", variant.baseName)

        // add SDK classes
        source = variant.javaCompiler.source

        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompiler.classpath.files) + files(ext.androidJar)

        ext.androidDoc = "${android.sdkDirectory}/docs/reference"

        options.linksOffline("http://d.android.com/reference", ext.androidDoc)
        options.links("http://docs.oracle.com/javase/7/docs/api/")
        options.links("http://d.android.com/reference/")

        exclude '*BuildConfig.java'
        exclude '*R.java'
        exclude '*impl*'
        exclude '*tests*'
    }
}

回答1:


If you are following standard project structure then use:

apply plugin: 'java'

javadoc {
    source = sourceSets.main.allJava
    classpath = configurations.compile
}

If not then you need to specify the include closure. Add the closure like:

include 'path/to/directory/*'

If include closure is not working then add sourceSet closure with srcDir pointing to the module/java directory:

sourceSets {
    build {
        java.srcDir file('src/main/java')

    }
}

And after that run $gradle javadoc command. Then check your build directory for html files having all javadocs. Note: Replace srcDir with your root package path.



来源:https://stackoverflow.com/questions/45997976/how-generate-javadoc-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!