17

我正在尝试运行sbt test:doc,但看到许多类似于以下的警告:

[警告] /Users/tleese/code/my/stuff/src/test/scala/com/my/stuff/common/tests/util/NumberExtractorsSpecs.scala:9:找不到任何成员链接“com.my .stuff.common.util.IntExtractor”。

问题似乎是从测试源到主要源的 Scaladoc 引用无法正确链接。知道我可能做错了什么或需要配置吗?

以下是我的 Build.scala 的相关部分:

val docScalacOptions = Seq("-groups", "-implicits", "-external-urls:[urls]")

scalacOptions in (Compile, doc) ++= docScalacOptions
scalacOptions in (Test, doc) ++= docScalacOptions
autoAPIMappings := true
4

3 回答 3

6

不确定这是否是一个令人满意的解决方案,但是......

Scaladoc 当前期望成对的 jar 和 URL 来使外部链接正常工作。您可以强制 sbt 使用 .jar 链接内部依赖项exportJars。比较值

$ show test:fullClasspath

设置前后exportJars。接下来,获取正在使用的 JAR 的名称并将其链接到您将上传到的 URL。

scalaVersion := "2.11.0"

autoAPIMappings := true

exportJars := true

scalacOptions in (Test, doc) ++= Opts.doc.externalAPI((
  file(s"${(packageBin in Compile).value}") -> url("http://example.com/")) :: Nil)

现在我看到了test:doc一个 Scaladoc,其中包含我的foo.IntExtractor.

于 2014-04-20T00:53:32.573 回答
2

使用尤金回答中的想法,我制作了以下片段。它使用sbt手册apiMapping中建议的 sbt 变量。不幸的是,它没有说明如何处理托管依赖项,即使小节标题也是如此。

// External documentation

/* You can print computed classpath by `show compile:fullClassPath`.
 * From that list you can check jar name (that is not so obvious with play dependencies etc).
 */
val documentationSettings = Seq(
  autoAPIMappings := true,
  apiMappings ++= {
    // Lookup the path to jar (it's probably somewhere under ~/.ivy/cache) from computed classpath
    val classpath = (fullClasspath in Compile).value
    def findJar(name: String): File = {
      val regex = ("/" + name + "[^/]*.jar$").r
      classpath.find { jar => regex.findFirstIn(jar.data.toString).nonEmpty }.get.data // fail hard if not found
    }

    // Define external documentation paths
    Map(
      findJar("scala-library") -> url("http://scala-lang.org/api/" + currentScalaVersion + "/"),
      findJar("play-json") -> url("https://playframework.com/documentation/2.3.x/api/scala/index.html")
    )
  }
)
于 2015-01-21T12:41:42.807 回答
1

这是@phadej对答案的修改。不幸的是,该答案仅适用于 Unix/Linux,因为它假定路径分隔符是/. 在 Windows 上,路径分隔符是\.

以下适用于所有平台,并且更习惯于恕我直言:

/* You can print the classpath with `show compile:fullClassPath` in the SBT REPL.
 * From that list you can find the name of the jar for the managed dependency.
 */
lazy val documentationSettings = Seq(
  autoAPIMappings := true,
  apiMappings ++= {
    // Lookup the path to jar from the classpath
    val classpath = (fullClasspath in Compile).value
    def findJar(nameBeginsWith: String): File = {
      classpath.find { attributed: Attributed[java.io.File] => (attributed.data ** s"$nameBeginsWith*.jar").get.nonEmpty }.get.data // fail hard if not found
    }
    // Define external documentation paths
    Map(
      findJar("scala-library") -> url("http://scala-lang.org/api/" + currentScalaVersion + "/"),
      findJar("play-json") -> url("https://playframework.com/documentation/2.3.x/api/scala/index.html")
    )
  }
)
于 2015-07-09T15:12:24.420 回答