GithubHelp home page GithubHelp logo

isabella232 / sbt-unidoc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sbt/sbt-unidoc

0.0 0.0 0.0 119 KB

sbt plugin to create a unified Scaladoc or Javadoc API document across multiple subprojects.

License: Apache License 2.0

Scala 100.00%

sbt-unidoc's Introduction

sbt-unidoc

sbt plugin to unify scaladoc/javadoc across multiple projects.

how to add this plugin

For sbt 1.x (requires sbt 1.5.x and above) add the following to your project/plugins.sbt:

addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")

Note: We changed the organization from "com.eed3si9n" to "com.github.sbt".

For older sbt 1.x and sbt 0.13 add the following to your project/plugins.sbt:

addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.3")

how to unify scaladoc

  1. Enable ScalaUnidocPlugin in your root project's settings.

Note: If one of your subprojects is defining def macros, add scalacOptions in (ScalaUnidoc, unidoc) += "-Ymacro-expand:none" to the root project's setting to temporary halt the macro expansion.

Here's an example setup using multi-project build.sbt:

ThisBuild / organization := "com.example"
ThisBuild / version := "0.1-SNAPSHOT"
ThisBuild / scalaVersion := scalaVersion := "2.12.15"
ThisBuild / autoAPIMappings := true

val library = (project in file("library"))
  .settings(
    name := "foo-library"
  )

val app = (project in file("app"))
  .dependsOn(library)
  .settings(
    name := "foo-app"
  )

val root = (project in file("."))
  .enablePlugins(ScalaUnidocPlugin)
  .aggregate(library, app)
  .settings(
    name := "foo"
  )

From the root project, run unidoc task:

foo> unidoc
...
[info] Generating Scala API documentation for main sources to /unidoc-sample/target/scala-2.10/unidoc...
[info] Scala API documentation generation successful.
[success] Total time: 10 s, completed May 16, 2013 12:57:10 AM

A Scala unidoc is created under crossTarget / "unidoc" containing entities from all projects under the build.

how to exclude a project

  1. Construct ScalaUnidoc / unidoc / unidocProjectFilter in the root project's settings.
val root = (project in file("."))
  .enablePlugins(ScalaUnidocPlugin)
  .aggregate(library, app)
  .settings(
    name := "foo",
    ScalaUnidoc / unidoc / unidocProjectFilter := inAnyProject -- inProjects(app)
  )

This will skip Scaladoc for the app project.

how to include multiple configurations

  1. Construct ScalaUnidoc / unidoc / unidocConfigurationFilter in the root project's settings.
val root = (project in file("."))
  .enablePlugins(ScalaUnidocPlugin)
  .aggregate(library, app)
  .settings(
    name := "foo",
    TestScalaUnidoc / unidoc / unidocConfigurationFilter := inConfigurations(Compile, Test)
  )

Running test:unidoc will now create unidoc including both Compile and Test configuration.

how to publish Scala unidoc to Github Pages

Add sbt-site and sbt-ghpages to your project/site.sbt:

addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.3.2")

addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")

Then in build.sbt import GitKeys,

import com.typesafe.sbt.SbtGit.GitKeys._

Add ScalaUnidoc / packageDoc / mappings to the site's mapping:

val root = (project in file("."))
  .enablePlugins(ScalaUnidocPlugin, GhpagesPlugin)
  .aggregate(library, app)
  .settings(
    name := "foo",
    ScalaUnidoc / siteSubdirName := "latest/api",
    addMappingsToSiteDir(ScalaUnidoc / packageDoc / mappings, ScalaUnidoc / siteSubdirName),
    gitRemoteRepo := "[email protected]:user/foo.git"
  )

Here's how to preview and publish it:

foo> previewSite
foo> ghpagesPushSite

how to unify javadoc

  1. Enable GenJavadocPlugin in child projects.
  2. Enable JavaUnidocPlugin in the root project.
ThisBuild / organization := "com.example"
ThisBuild / version := "0.1-SNAPSHOT"
ThisBuild / scalaVersion := scalaVersion := "2.12.15"
ThisBuild / autoAPIMappings := true

val library = (project in file("library"))
  .enablePlugins(GenJavadocPlugin)
  .settings(
    name := "foo-library"
  )

val app = (project in file("app"))
  .enablePlugins(GenJavadocPlugin)
  .dependsOn(library)
  .settings(
    name := "foo-app"
  )

val root = (project in file("."))
  .enablePlugins(JavaUnidocPlugin)
  .aggregate(library, app)
  .settings(
    name := "foo"
  )

GenJavadocPlugin adds a compiler plugin called genjavadoc, which generates Java source code into target/java from Scala source code, so javadoc can be generated. The main benefits of javadoc are having natural documentation for Java API, IDE support, and Java enum support. However, the genjavadoc does not always generate compilable Java code; if you see misbehavior please open an issue with genjavadoc.

First clean all projects (in the above, root aggreates both children), then run unidoc task from the root project:

foo> clean
[success] Total time: 0 s, completed May 16, 2013 1:13:55 AM
foo> unidoc
[info] Compiling 10 Scala sources ...
[info] Generating Java API documentation for main sources to /unidoc-sample/target/javaunidoc...
[warn] Loading source file /unidoc-sample/app/target/java/foo/App$.java...
....
[info] Java API documentation generation successful.
[success] Total time: 1 s, completed May 16, 2013 1:14:12 AM

Cleaning is necessary since genjavadoc does not track the correspondence between Scala sources and emitted Java files, leading to extraneous Java sources when deleting classes. A Java unidoc is created under target/javaunidoc containing entities from all projects under the build.

how to publish genjavadoc instead of scaladoc

  1. Enable PublishJavadocPlugin in child projects.

This will substitute the Compile / packageDoc with Genjavadoc / packageDoc to use the enhanced Javadoc.

how to unify both Scaladoc and Javadoc

  1. Enable GenJavadocPlugin (or PublishJavadocPlugin) in child projects.
  2. Enable ScalaUnidocPlugin and JavaUnidocPlugin in the root project.

This combines both Scala unidoc settings and Java unidoc settings. Run unidoc from the root project to execute both.

credits

The original implementation of unidoc task was written by Peter Vlugter (@pvlugter) for Akka project. I took Unidoc.scala in akka/akka@ed40dff7d7353c5cb15b7408ec049116081cb1fc and refactored it. sbt-unidoc is Open Source and available under the Apache 2 License.

sbt-unidoc's People

Contributors

2m avatar daenyth avatar eed3si9n avatar emanresusername avatar halcat0x15a avatar ktoso avatar liff avatar magnolia-k avatar pikinier20 avatar rkuhn avatar scala-steward avatar seratch avatar sethtisue avatar sullis avatar travisbrown avatar xirc avatar xuwei-k avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.