我可以将 sbt 的 `apiMappings` 设置用于托管依赖项吗? [英] Can I use sbt's `apiMappings` setting for managed dependencies?

查看:25
本文介绍了我可以将 sbt 的 `apiMappings` 设置用于托管依赖项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我用 sbt 生成的 ScalaDoc 链接到外部库,在 sbt 0.13 中,我们有 autoAPIMappings 应该为声明它们的库添加这些链接 apiURL.但在实践中,我使用的库都没有在其 pom/ivy 元数据中提供这一点,而且我怀疑其中一些库永远不会这样做.

I'd like the ScalaDoc I generate with sbt to link to external libraries, and in sbt 0.13 we have autoAPIMappings which is supposed to add these links for libraries that declare their apiURL. In practice though, none of the libraries I use provide this in their pom/ivy metadata, and I suspect some of these libraries will never do so.

apiMappings 设置应该有助于解决这个问题,但它的类型为 Map[File, URL],因此适用于为非托管依赖项设置 doc url.托管依赖项被声明为 sbt.ModuleID 的实例,并且不能直接插入到该映射中.

The apiMappings setting is supposed to help with just that, but it is typed as Map[File, URL] and hence geared towards setting doc urls for unmanaged dependencies. Managed dependencies are declared as instances of sbt.ModuleID and cannot be inserted directly in that map.

我能否以某种方式填充 apiMappings 设置以将 URL 与托管依赖项相关联?

Can I somehow populate the apiMappings setting with something that will associate an URL with a managed dependency ?

一个相关的问题是:sbt 是否提供了从 ModuleID 获取 File 的惯用方法?我想我可以尝试评估一些类路径并返回 Files 以尝试将它们映射到 ModuleIDs 但我希望有更简单的东西.

A related question is: does sbt provide an idiomatic way of getting a File from a ModuleID? I guess I could try to evaluate some classpaths and get back Files to try and map them to ModuleIDs but I hope there is something simpler.

注意:这与 https://stackoverflow.com 有关/questions/18747265/sbt-scaladoc-configuration-for-the-standard-library/18747266,但该问题的不同之处在于链接到标准库的 scaladoc,为此有一个众所周知的 File scalaInstance.value.libraryJar,在本例中并非如此.

Note: this is related to https://stackoverflow.com/questions/18747265/sbt-scaladoc-configuration-for-the-standard-library/18747266, but that question differs by linking to the scaladoc for the standard library, for which there is a well known File scalaInstance.value.libraryJar, which is not the case in this instance.

推荐答案

我设法通过执行以下操作来使此工作用于引用 scalaz 和 play:

I managed to get this working for referencing scalaz and play by doing the following:

apiMappings ++= {
  val cp: Seq[Attributed[File]] = (fullClasspath in Compile).value
  def findManagedDependency(organization: String, name: String): File = {
    ( for {
        entry <- cp
        module <- entry.get(moduleID.key)
        if module.organization == organization
        if module.name.startsWith(name)
        jarFile = entry.data
      } yield jarFile
    ).head
  }
  Map(
      findManagedDependency("org.scalaz",        "scalaz-core") -> url("https://scalazproject.ci.cloudbees.com/job/nightly_2.10/ws/target/scala-2.10/unidoc/")
    , findManagedDependency("com.typesafe.play", "play-json")   -> url("http://www.playframework.com/documentation/2.2.1/api/scala/")
  )
}

当然是天啊.

这篇关于我可以将 sbt 的 `apiMappings` 设置用于托管依赖项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆