如何使 javadoc doclava doclet 与 gradle 一起工作

How to make javadoc doclava doclet works with gradle

我正在用 gradle 使用 java 插件构建一个项目,我还想使用 doclava doclet

构建 javadoc

这是模块 build.gradle

的相关部分
apply plugin: 'java'
javadoc {
    source = sourceSets.main.allJava

    ...

    exclude "com/mobaires/sdk/api/debug/**"

    options.windowTitle = "SDK"
    options.docTitle = "SDK"

    options.doclet = "com.google.doclava.Doclava"
    options.docletpath = [file("libs/doclava-1.0.5.jar")]    
}

当我 运行 ./gradlew javadoc 我得到这个错误

16:24:46.030 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :javadoc FAILED
16:24:46.035 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 0.695 secs, idle: 0.0040 secs
16:24:46.044 [ERROR] [org.gradle.BuildExceptionReporter] 
16:24:46.045 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
16:24:46.045 [ERROR] [org.gradle.BuildExceptionReporter] 
16:24:46.046 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:24:46.046 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':javadoc'.
16:24:46.047 [ERROR] [org.gradle.BuildExceptionReporter] > Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '.../build/tmp/javadoc/javadoc.options'
16:24:46.048 [ERROR] [org.gradle.BuildExceptionReporter] 
16:24:46.048 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
16:24:46.049 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 
16:24:46.055 [LIFECYCLE] [org.gradle.BuildResultLogger] 
16:24:46.058 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
16:24:46.059 [LIFECYCLE] [org.gradle.BuildResultLogger] 
16:24:46.060 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 9.297 secs

有人可以用 Gradle 使它与 doclava 一起工作吗?

查看错误日志中提到的 javadoc.options 后,它说

-classpath '... all the classpath here ...'
-d '.../build/docs/javadoc'
-doclet 'com.google.doclava.Doclava'
-docletpath '../libs/doclava-1.0.5.jar'
-doctitle 'XXXX'
-quiet 
-windowtitle 'XXXX'
'... classes to get javadoc'

问题是 gradle 将 doctitle 和 windowtitle 作为参数传递给 doclava doclet 不支持的 javadoc 命令。

深入研究 org.gradle.api.tasks.javadoc.Javadoc 代码,我发现了一个可行的解决方法。我只是将 title = null 添加到 build.gradle file

中的 javadoc 任务
javadoc {
    source = sourceSets.main.allJava
    ...
    exclude "com/mobaires/sdk/api/debug/**"

    title = null

    options.doclet = "com.google.doclava.Doclava"
    options.docletpath = [file("libs/doclava-1.0.5.jar")]    
}

希望对其他人有所帮助:)