sbt / sbt-unidoc

sbt plugin to create a unified Scaladoc or Javadoc API document across multiple subprojects.
Apache License 2.0
124 stars 27 forks source link

Exclude a package from all projects #56

Open skvithalani opened 6 years ago

skvithalani commented 6 years ago

We want to exclude a particular package named "internal" from scaladoc and javadoc for all projects. We have UnidocSite plugin as follows:

object UnidocSite extends AutoPlugin {
  import sbtunidoc.{BaseUnidocPlugin, JavaUnidocPlugin, ScalaUnidocPlugin}
  import JavaUnidocPlugin.autoImport._
  import ScalaUnidocPlugin.autoImport._
  import BaseUnidocPlugin.autoImport.unidoc

  import com.typesafe.sbt.site.SitePlugin.autoImport._

  override def requires: Plugins = ScalaUnidocPlugin && JavaUnidocPlugin

  def excludeJavadoc: Set[String] = Set("internal", "scaladsl", "csw_protobuf")

  def excludeScaladoc: String     = Seq("internal", "csw_protobuf", "akka").mkString(":")

  override def projectSettings: Seq[Setting[_]] = Seq(
    siteSubdirName in ScalaUnidoc := "/api/scala",
    addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), siteSubdirName in ScalaUnidoc),
    siteSubdirName in JavaUnidoc := "/api/java",
    filterNotSources(sources in (JavaUnidoc, unidoc), excludeJavadoc),
    addMappingsToSiteDir(mappings in (JavaUnidoc, packageDoc), siteSubdirName in JavaUnidoc),

    scalacOptions in (ScalaUnidoc, unidoc) ++= Seq("-skip-packages", excludeScaladoc),

    autoAPIMappings := true
  )

  def filterNotSources(filesKey: TaskKey[Seq[File]], subPaths: Set[String]): Setting[Task[Seq[File]]] = {
    filesKey := filesKey.value.filterNot(file => subPaths.exists(file.getAbsolutePath.contains))
  }
}

But somehow "internal" package gets excluded only from javadoc and not from scaladoc.

Is there something we are missing ?

nachmikott commented 5 years ago

Hey @skvithalani , I hope all is well. I'm wondering, did this ever work for you? I have a similar issue, where I don't want certain packages in a sbt unidoc.

skvithalani commented 5 years ago

Hello @nachmikott, for packages to be excluded from scala, we make all the members in that package private/package private. If none of the members are visible to outer world then sbt-unidoc does not include that package in scaladoc.

So, if we don't have any visible members, we don't need scaladoc for it. That's the approach.

vbmacher commented 12 months ago

Hello all, I didnt want to start a new ticket for this, because I think it's related. My question:

Is it possible to exclude documentation of generated sources? I mean the ones generated with Compile / sourceGenerators?

Even though this question applies generally (e.g. for the generated parsers, etc.) - in my specific case, I have zipped source code of some external library, because it's not published anywhere. I dont want to include/generate the documentation of this external source.

Example part of my build.sbt:

lazy val myproject = project
        .settings(
          Compile / sourceGenerators += unzipMyLibraryTask,
          ...
        )

lazy val root = (project in file("."))
        .enablePlugins(ScalaUnidocPlugin)
        .aggregate(myproject)
        .settings(
          ScalaUnidoc / unidoc / scalacOptions ++= Seq("-skip-packages", "com.mylibrary")  // this is what I tried, but doesnt work..
        )

If there is no other option, I would include it, but the problem is the library source code is not perfectly written and so the unidoc shows errors and refuses to continue. I really don't want to spend any time of fixing the library.

Thanks for any advice!