java 如何使用 Gradle 生成 javadoc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45997976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How generate javadoc with Gradle?
提问by Oscar Caballero Pozas
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.
我想从 aar lib 文件中生成 javadoc,但我的实际任务不起作用并以错误结束。我对 gradle 有点迷茫。
Where should generate javadocs?
应该在哪里生成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*'
}
}
回答by Abhijit Maity
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
闭包。添加闭包,如:
include 'path/to/directory/*'
If include closure is not working then add sourceSet
closure with srcDir
pointing to the module/java
directory:
如果包含闭包不起作用,则添加sourceSet
闭包并srcDir
指向module/java
目录:
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 srcDirwith your root package path.
然后运行$gradle javadoc
命令。然后检查您的构建目录中是否有包含所有 javadoc 的 html 文件。注意:将srcDir替换为您的根包路径。