Unmanaged docs with sbt

This is an sbt question.

My project implements Java bridges to a Scala library. All the public code is Java. I’ve given up on trying to run javadoc within sbt, so I generate the docs with a separate script. My problem is publishing: I need publishSigned to use the docs I’ve generated, not whatever is produced by the doc task.

I finally found a way, but it feels more like a hack than anything else:

This / Compile / doc := baseDirectory.value / "docs"

It works, though: publishSigned generates and signs a jar using docs, where my javadoc-generated content lives.

I even went a step further and made the doc task run my script:

This / Compile / doc := {
   import scala.sys.process._
   val script = baseDirectory.value / "makedocs.sh"
   val out    = baseDirectory.value / "docs"
   s"zsh $script" ! streams.value.log
   out
}

This is even more of a hack, especially since makedocs.sh uses sbt to calculate the class path!

There has to be something cleaner… Any advice?

1 Like

In case someone is curious, this is what I settled with:

import scala.sys.process._

This / Compile / doc := {
   val classpath = Attributed.data((Compile / fullClasspath).value).mkString(":")
   val script = (baseDirectory.value / "makedocs.sh").toString
   Seq("zsh", script, classpath) ! streams.value.log
   baseDirectory.value / "docs"
}

I’m passing the class path to my script so it doesn’t need to run sbt to build it. Everything works and it’s clean enough for now.

2 Likes