Class Javadoc

All Implemented Interfaces:
Generator, Renamable, ResourceProvider

public class Javadoc extends JavaTool

The Javadoc generator provides the resource JavadocDirectory, a directory that contains generated javadoc files.

No attempt is made to define dedicated types for Javadoc tool options. Instead, options are passed as strings, as suggested by the ToolProvider API. Notable exceptions exist for options that are directly related to resource types originating from the builder context (such as files, directory trees, and paths).

By default, the generator builds the Javadoc for the project passed to the constructor. In some cases – such as generating a shared Javadoc for multiple projects – this behavior is not desired. In these cases, the project(s) for which Javadoc is generated can be configured via projects(Stream).

The classpath and module-path for the Javadoc tool invocation are assembled by requesting the CodeContributions with intents Consume, Reveal and Expose from the configured project(s).

The JavaSourceFiles to be processed are obtained by requesting resources of JavaTypes.JavaSourceTreeType with intents Supply and Expose from the configured project(s). This default behavior can be overridden by setting the sources explicitly using one or more invocations of the addSources methods.

JPMS support

When the sources contain a module-info.java, or when the module mode is set to ModuleMode.MODULE, generation uses the module-path (--module-path) for code contributions that contain a module descriptor. Non-modular code contributions remain on the classpath (-cp). In ModuleMode.AUTO mode (the default), module compilation is activated automatically when a module-info.java is found among the sources.

  • Constructor Details

    • Javadoc

      public Javadoc(Project project)
      Instantiates a new java compiler.
      Parameters:
      project - the project
  • Method Details

    • projects

      public Javadoc projects(Stream<Project> projects)
      Sets the projects to generate javadoc for.
      Parameters:
      projects - the projects
      Returns:
      the javadoc
    • destination

      public Path destination()
      Returns the destination directory. Defaults to "doc".
      Returns:
      the destination
    • destination

      public Javadoc destination(Path destination)
      Sets the destination directory. The Path is resolved against the project's build directory (see Project.buildDirectory()).
      Parameters:
      destination - the new destination
      Returns:
      the javadoc generator
    • addSources

      Adds the source tree.
      Parameters:
      sources - the sources
      Returns:
      the javadoc generator
    • addSources

      public final Javadoc addSources(Path directory, String pattern)
      Adds the files from the given directory matching the given pattern. Short for addSources(project().newFileTree(directory, pattern, JavaSourceFile.class)).
      Parameters:
      directory - the directory
      pattern - the pattern
      Returns:
      the javadoc generator
    • addSources

      public final Javadoc addSources(Stream<FileTree<JavaSourceFile>> sources)
      Adds the sources.
      Parameters:
      sources - the sources
      Returns:
      the java compiler
    • hasModuleInfo

      protected boolean hasModuleInfo()
      Description copied from class: JavaTool
      Checks whether a module-info.java exists among the configured sources.
      Specified by:
      hasModuleInfo in class JavaTool
      Returns:
      true, if module-info.java is present
    • tagletpath

      public Javadoc tagletpath(Stream<? extends CodeContribution> classpathElements)
      Adds the given classpath elements to the tagletpath. The classpath elements can be classpath elements or modules.
      Parameters:
      classpathElements - the classpath elements
      Returns:
      the javadoc
    • taglets

      public Javadoc taglets(Stream<String> taglets)
      Adds the given taglets.
      Parameters:
      taglets - the taglets
      Returns:
      the javadoc
    • doProvide

      protected <T extends Resource> Collection<T> doProvide(ResourceRequest<T> requested)
      Description copied from class: AbstractProvider
      Invoked by ResourceProviderSpi.provide(ResourceRequest) after checking if the invocation is allowed.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      T - the generic type
      Parameters:
      requested - the request for resources
      Returns:
      the stream