Search code examples
sbtjavadoc

Enforce Javadoc version in SBT


I just started to work on a large project that uses SBT for building. I got a new computer with Java 8 installed, but the rest of the team still uses Java 7. That's not a problem as far as the code goes because we're all set to generate v7 byte-code.

The problems arise when attempting to publishing the project using the publishLocal action. Please keep in mind though that I am very new to SBT and some things I say/assume may not be accurate.

We use sbt 0.13. When I run the command sbt publishLocal, it runs the doc action, which in turn runs javadoc to generate the documentation. Since I have java 1.8 installed, it uses the corresponding version of javadoc, which let's be honest is a real pain in the neck, complaining about every single missing @return or @param, self-closing elements (e.g. "<p/>") and such, and returning a non-zero value because of this, thus making the publication fail. However, as I mentioned, the project is fairly big and, although it would be better to complete the javadoc documentation, it's not feasible at the moment.

Luckily, javadoc 8 provides an option do disable the pedantry: -Xdoclint:none will make it quiet about pretty much anything, allowing me to run the publish action by adding it to the javacOptions.

However, as I said, the other team members are still using java 7, and, unfortunately, javadoc 7 does not support that option, so if I push the build.sbt file with this option it will fail on other machines.

So now I'm wondering what I can do. The way I see it, there's a number of options, none of which seems "simple enough" to fix that stupid problem:

  • downgrade locally to java 7 (not a big fan of having two concurrent versions lying around)
  • have all other team members upgrade to java 8 (pain for them)
  • fix all javadoc problems in the whole project (pain for everyone)

Hopefully, there's another option I'm missing that would allow me, for instance, to set the javadoc options based on the java version? Or anything else that doesn't require touching anything else than the build.sbt file...

Thanks!

David


Solution

  • Yes, you can set the Javadoc options based on the Java version:

    javacOptions in Compile ++=
      sys.props("java.version").split('.') match {
        case Array("1", n, _*) if n.toInt <= 7 =>
          Seq()
        case _ =>
          Seq("-Xdoclint:none")
      }