公认的答案是好的,但是当关于确切项目依赖关系的假设不成立时,它就会失败。这是一个可能有用的变体:
apiMappings ++= {
def mappingsFor(organization: String, names: List[String], location: String, revision: (String) => String = identity): Seq[(File, URL)] =
for {
entry: Attributed[File] <- (fullClasspath in Compile).value
module: ModuleID <- entry.get(moduleID.key)
if module.organization == organization
if names.exists(module.name.startsWith)
} yield entry.data -> url(location.format(revision(module.revision)))
val mappings: Seq[(File, URL)] =
mappingsFor("org.scala-lang", List("scala-library"), "http://scala-lang.org/api/%s/") ++
mappingsFor("com.typesafe.akka", List("akka-actor"), "http://doc.akka.io/api/akka/%s/") ++
mappingsFor("com.typesafe.play", List("play-iteratees", "play-json"), "http://playframework.com/documentation/%s/api/scala/index.html", _.replaceAll("[\\d]$", "x"))
mappings.toMap
}
(此处包含scala-library 是多余的,但用于说明目的。)
如果你执行mappings foreach println,你会得到类似的输出(注意我的依赖项中没有Akka):
(/Users/michaelahlers/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar,http://scala-lang.org/api/2.11.7/)
(/Users/michaelahlers/.ivy2/cache/com.typesafe.play/play-iteratees_2.11/jars/play-iteratees_2.11-2.4.6.jar,http://playframework.com/documentation/2.4.x/api/scala/)
(/Users/michaelahlers/.ivy2/cache/com.typesafe.play/play-json_2.11/jars/play-json_2.11-2.4.6.jar,http://playframework.com/documentation/2.4.x/api/scala/)
这种方法:
- 允许与模块标识符不匹配或匹配多个。
- 简洁地支持多个模块链接相同的文档。
- 或者,将
Nil 提供给names,组织的所有模块。
- 以模块为版本授权。
这些改进允许您创建一个单独的 SBT 文件(称为 scaladocMappings.sbt),该文件可以在一个位置进行维护,并且可以轻松复制并粘贴到任何项目中。