我正在使用java插件用gradle构建一个项目,我还想使用doclava doclet 构建javadoc
这是模块构建的相关部分。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一起工作吗?
查看错误日志中提到的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代码,我找到了一个行之有效的解决方法。我只是在build.gradle文件中的javadoc任务中添加了title=null
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")]
}
我希望它能帮助其他人:)