Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt ignores my scaladoc settings

I am trying to follow the sbt documentation for scaladoc generation. I have a multi project (i.e. aggregate with sub-projects) build which was a ./build.sbt for general settings. I added the last entry in the following example:

scalacOptions in ThisBuild ++= Seq("-deprecation", "-unchecked", "-feature")

scalacOptions in ThisBuild += "-no-specialization"

// API docs
scalacOptions in ThisBuild in (Compile,doc) ++= Seq(
  "-diagrams", "-doc-title", name.value
)

This doesn't have any effect. Neither does scaladoc attempt to generate diagrams, nor is the main document title set, so simply these settings are ignored. Likewise, if I add a "-foobar" option, no error appears.

How to fix this (in build.sbt, I don't want to go into project/Build.scala, thanks)

like image 954
0__ Avatar asked Feb 14 '23 16:02

0__


2 Answers

So as Josh said, somehow the ThisBuild / ThisProject stuff overwrites each other.

The solution was to migrate the project/Build.sbt from the sbt 0.12 times into build.sbt, which fortunately was mostly copy + paste, as sbt 0.13 now accepts a lot of normal Scala code in there (not objects, though...).

I then defined

lazy val commonSettings = Project.defaultSettings ++ Seq(
  ...
  scalacOptions  ++= Seq(
    "-no-specialization",
    // "-Xelide-below", "INFO", // elide debug logging!
    "-deprecation", "-unchecked", "-feature"
  ),
  // API docs:
  scalacOptions in (Compile, doc) ++= Seq(
    "-diagrams",
    "-diagrams-dot-path", "/usr/local/bin/dot",
    // "-diagrams-dot-timeout", "20", "-diagrams-debug",
    "-doc-title", name.value
  ),
  ...
)

And it works.


The last annoying bit is the requirement for "-diagrams-dot-path", this truly sucks as it is an open source project, and I don't want to force that path onto anyone else. Why the heck doesn't it find dot on my $PATH which does include /user/local/bin?

like image 127
0__ Avatar answered Feb 23 '23 04:02

0__


So, if you run inspect on the doc task, you'll find that the setting sbt is looking for is:

scalacOptions in ThisProject in (Compile, doc)

ThisBuild is reserved for things that are re-used across projects (or shared that way), like scalaVersions.

Now, the issue is that scalacOptions in ThisProject in (Compile,doc) will first read from scalacOptions in ThisProject in Compile before checking scalacOptions in ThisProject before going down to ThisBuild.

Most likely, something is specifying the scalacOptions at a higher precedence and your setting is ignored. You should drop the in ThisBuild and things should work for the root project.

like image 36
jsuereth Avatar answered Feb 23 '23 06:02

jsuereth