我使用 sbt 0.13.5。
没有开箱即用的方法来具有在 scaladoc 中具有 Javadoc 链接的功能。根据我的理解,这不是 sbt 的错,而是 scaladoc 的工作方式。正如Josh在他的评论中指出的那样,您应该向 scaladoc 报告。
然而,我想出了一个解决方法——对生成的docscaladoc 进行后处理,以便替换 Java URL 以形成正确的 Javadoc 链接。
文件scaladoc.sbt应该放在 sbt 项目中,每当doc任务执行时,通过fixJavaLinksTask任务的后处理就会启动。
注意有很多硬编码的路径,所以请谨慎使用(也就是你认为合适的抛光)。
import scala.util.matching.Regex.Match
autoAPIMappings := true
// builds -doc-external-doc
apiMappings += (
file("/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar") ->
url("http://docs.oracle.com/javase/8/docs/api")
)
lazy val fixJavaLinksTask = taskKey[Unit](
"Fix Java links - replace #java.io.File with ?java/io/File.html"
)
fixJavaLinksTask := {
println("Fixing Java links")
val t = (target in (Compile, doc)).value
(t ** "*.html").get.filter(hasJavadocApiLink).foreach { f =>
println("fixing " + f)
val newContent = javadocApiLink.replaceAllIn(IO.read(f), fixJavaLinks)
IO.write(f, newContent)
}
}
val fixJavaLinks: Match => String = m =>
m.group(1) + "?" + m.group(2).replace(".", "/") + ".html"
val javadocApiLink = """\"(http://docs\.oracle\.com/javase/8/docs/api/index\.html)#([^"]*)\"""".r
def hasJavadocApiLink(f: File): Boolean = (javadocApiLink findFirstIn IO.read(f)).nonEmpty
fixJavaLinksTask <<= fixJavaLinksTask triggeredBy (doc in Compile)