问题描述
我想从aar lib文件中生成javadoc,但是我的实际任务无法正常工作并出现错误。
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.
在哪里生成javadocs?
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*'
}
}
推荐答案
如果您遵循标准项目结构,请使用:
If you are following standard project structure then use:
apply plugin: 'java'
javadoc {
source = sourceSets.main.allJava
classpath = configurations.compile
}
如果没有,则需要指定 include
关闭。添加闭包,例如:
If not then you need to specify the include
closure. Add the closure like:
include 'path/to/directory/*'
如果include闭包不起作用,则添加 sourceSet
闭包和 srcDir
指向 module / java
目录:
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')
}
}
之后,运行 $ gradle javadoc
命令。
然后检查构建目录中是否包含所有javadocs的html文件。
注意:将 srcDir 替换为您的根软件包路径。
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.
这篇关于如何用Gradle生成Javadoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!