0

I hit a MissingRequirementError when I try to invoke scaladoc from within an sbt task.

Using any version of sbt 0.13.x, start with this 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))
}

Then run sbt scaladoc, and behold (during 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)

What is wrong here? I've already tried fork := true and different combinations of sbt/scala versions to no avail.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
gladed
  • 1,705
  • 1
  • 17
  • 25
  • What are you doing it? Is this a kind of exercise? There's `sbt doc` already. – Jacek Laskowski Oct 16 '14 at 17:57
  • I need programmatic access to the ScalaDoc objects so that I can generate alternate documentation. – gladed Oct 16 '14 at 18:14
  • The solution [here](http://stackoverflow.com/questions/22668012/test-in-eclipse-works-but-sbt-throws-missingrequirementerror-object-scala-runti) seems to work, but there should be a "correct" way to locate the scala-library dependency. – gladed Oct 16 '14 at 18:34

1 Answers1

1

It seems you need to provide scala-library (and indeed, any other dependencies) directly to the 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))
}
gladed
  • 1,705
  • 1
  • 17
  • 25