Javadoc Formatter Gradle Plugin

The Javadoc Formatter Gradle plugin lets you format project Javadoc comments using the Liferay Javadoc Formatter tool. The tool lets you generate:

  • Default @author tags to all classes.
  • Comment stubs to classes, fields, and methods.
  • Missing @Override annotations.
  • An XML representation of the Javadoc comments, which can be used by tools in order to index the Javadocs of the project.

The plugin has been successfully tested with Gradle 4.10.2.

Usage

To use the plugin, include it in your build script:

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.javadoc.formatter", version: "1.0.27"
    }

    repositories {
        maven {
            url "https://repository-cdn.liferay.com/nexus/content/groups/public"
        }
    }
}

apply plugin: "com.liferay.javadoc.formatter"

Since the plugin automatically resolves the Liferay Javadoc Formatter library as a dependency, you have to configure a repository that hosts the library and its transitive dependencies. The Liferay CDN repository hosts them all:

repositories {
    maven {
        url "https://repository-cdn.liferay.com/nexus/content/groups/public"
    }
}

Tasks

The plugin adds one task to your project:

NameDepends OnTypeDescription
formatJavadoc-FormatJavadocTaskRuns the Liferay Javadoc Formatter to format files.

FormatJavadocTask

Tasks of type FormatJavadocTask extend JavaExec, so all its properties and methods, like args and maxHeapSize, are available. They also have the following properties set by default:

Property NameDefault Value
argsJavadoc Formatter command line arguments
classpathproject.configurations.javadocFormatter
main"com.liferay.javadoc.formatter.JavadocFormatter"

Task Properties

Property NameTypeDefault ValueDescription
authorString"Brian Wing Shun Chan"The value of the @author tag to add at class level if missing. It sets the javadoc.author argument.
generateXMLbooleanfalseWhether to generate a XML representation of the Javadoc comments. The XML files are generated in the src/main/resources directory only if the Java files are contained in src/main/java. It sets the javadoc.generate.xml argument.
initializeMissingJavadocsbooleanfalseWhether to add comment stubs at the class, field, and method levels. If false, only the class-level @author is added. It sets the javadoc.init argument.
limitsList<String>[]The Java file name patterns, relative to workingDir, to include when formatting Javadoc comments. The patterns must be specified without the .java file type suffix. If empty, all Java files are formatted. It sets the javadoc.limit argument.
lowestSupportedJavaVersiondouble1.7If a method is annotated with the @SinceJava annotation and its value argument is greater than the value specified for the lowestSupportedJavaVersion property, then the @Override annotation is not automatically added, even if it is missing. It sets the javadoc.lowest.supported.java.version argument. See LPS-37353.
outputFilePrefixString"javadocs"The file name prefix of the XML representation of the Javadoc comments. If generateXML is false, this property is not used. It sets the javadoc.output.file.prefix argument.
updateJavadocsbooleanfalseWhether to fix existing comment blocks by adding missing tags. It sets the javadoc.update argument.

It is possible to use Closures and Callables as values for the String properties, to defer evaluation until task execution.

Task Methods

MethodDescription
FormatJavadocTask dirNames(Iterable<Object> limits)Adds Java file name patterns, relative to workingDir, to include when formatting Javadoc comments.
FormatJavadocTask dirNames(Object... limits)Adds Java file name patterns, relative to workingDir, to include when formatting Javadoc comments.

Additional Configuration

There are additional configurations that can help you use the Javadoc Formatter.

Liferay Javadoc Formatter Dependency

By default, the plugin creates a configuration called javadocFormatter and adds a dependency to the latest released version of the Liferay Javadoc Formatter. It is possible to override this setting and use a specific version of the tool by manually adding a dependency to the javadocFormatter configuration:

dependencies {
    javadocFormatter group: "com.liferay", name: "com.liferay.javadoc.formatter", version: "1.0.32"
}

If the java plugin is applied, the javadocFormatter configuration automatically extends from the compile configuration.

System Properties

It is possible to set the default values of the generateXML, initializeMissingJavadocs, limits, and updateJavadocs properties for a FormatJavadocTask task via system properties:

  • -D${task.name}.generate.xml=true
  • -D${task.name}.init=SomeClassName1,SomeClassName2,com.liferay.portal.**
  • -D${task.name}.limit=**/com/example/
  • -D${task.name}.update=true
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 1