如何使用Gradle生成javadoc?

我想从aar lib文件生成javadoc,但我的实际任务不起作用并完成错误。 我有点迷失了。

应该在哪里生成javadoc?

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*' } } 

如果您遵循标准项目结构,则使用:

 apply plugin: 'java' javadoc { source = sourceSets.main.allJava classpath = configurations.compile } 

如果没有,那么你需要指定include闭包。 添加闭包像:

 include 'path/to/directory/*' 

如果include closure无法正常工作,则使用指向module / java目录的srcDir添加sourceSet闭包:

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

然后运行$gradle javadoc命令。 然后检查您的构建目录中是否有包含所有javadoc的html文件。 注意:将srcDir替换为根程序包路径。