如何使用 Gradle 为软件包文档配置 Dokka ?



>我无法配置 Dokka 以包含我的软件包的文档,而无需使用文件系统根目录的完整绝对路径。我的 Gradle 文件中有(includes行是有问题的行(:

dokka {
outputFormat = 'html'
outputDirectory = "$projectDir/../doc"

configuration {
// Use to include or exclude non public members.
includeNonPublic = false
// Do not output deprecated members. Applies globally, can be overridden by packageOptions
skipDeprecated = false
// Emit warnings about not documented members. Applies globally, also can be overridden by packageOptions
reportUndocumented = true
// Do not create index pages for empty packages
skipEmptyPackages = true
includes = ["${projectDir}/app/src/main/kotlin/com/biexpertise/simplewebview/packages.md"]
}
}

什么时候,如果我遇到此错误,我会运行./gradlew dokka

> Task :app:dokka FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dokka'.
> org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String

如果我删除$projectDir并使用绝对路径,事情就会正常。是否可以改用相对路径?

所以这实际上是 dokka 的 Gradle 插件的问题,或者更具体地说,是 Groovy String 实现的问题。Groovy对字符串使用自己的GStringImpl,而不是String类,这会导致在将List<GStringImpl>转换为List<String>时出现问题(此强制转换不成功(。

最简单的解决方案是在包含上调用.toString(),如下所示:

includes = ["${projectDir}/app/src/main/kotlin/com/biexpertise/simplewebview/packages.md".toString()]

不过,这应该在 dokka 端修复,您可以在 GitHub 上提交错误报告

最新更新