我正在用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作为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")] }
我希望它能帮助别人:)