我使用java插件使用gradle构建项目,我还想使用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吗?
答案 0 :(得分:7)
在查看错误日志中提到的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作为javadoc命令的参数传递,而doclava doclet不支持这些参数。
潜入org.gradle.api.tasks.javadoc.Javadoc代码我发现了一个有效的解决方法。我只是将title = null添加到build.gradle文件中的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")]
}
我希望它能帮助别人:)