为什么自定义scaladoc任务抛出MissingRequirementError:找不到编译器镜像中的对象scala.annotation.Annotation?

时间:2014-10-16 17:34:54

标签: scala sbt scaladoc

当我尝试从某个sbt任务中调用scaladoc时,我遇到了MissingRequirementError。

使用任何版本的sbt 0.13.x,从这个build.sbt

开始
val scaladoc = taskKey[Unit]("run scaladoc")

scaladoc := {
  import scala.tools.nsc._
  val settings = new doc.Settings(error => print(error))
  settings.usejavacp.value = true
  val docFactory = new doc.DocFactory(new reporters.ConsoleReporter(settings), settings)
  val universe = docFactory.makeUniverse(Left((sources in Compile).value.map(_.absolutePath).toList))
}

然后运行sbt scaladoc,并且(在makeUniverse期间):

[info] Set current project to test (in build file:...)
scala.reflect.internal.MissingRequirementError: object scala.annotation.Annotation in compiler mirror not found.
  at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
  at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
  at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)

这里有什么问题?我已经尝试fork := true并且sbt / scala版本的不同组合无济于事。

1 个答案:

答案 0 :(得分:1)

您似乎需要直接向scala-library提供DocFactory(实际上,任何其他依赖项)。

scaladoc := {
  import scala.tools.nsc._
  val settings = new doc.Settings(error => print(error))
  val dependencyPaths = (update in Compile).value
    .select().map(_.absolutePath).mkString(java.io.File.pathSeparator)
  settings.classpath.append(dependencyPaths)
  settings.bootclasspath.append(dependencyPaths)
  val docFactory = new doc.DocFactory(new reporters.ConsoleReporter(settings), settings)
  val universe = docFactory.makeUniverse(Left((sources in Compile).value.map(_.absolutePath).toList))
}