/gradle-fix-javadoc-plugin

Primary LanguageKotlinGNU General Public License v3.0GPL-3.0

This is a gradle plugin to automatically remove doubled annotations caused by, for example, jetbrains annotations.

Usage

The fix-javadoc-plugin is available in the Gradle Plugin Portal.

plugins {
    id("com.jeff-media.fix-javadoc-plugin") version ("1.19")
}

The plugin will automatically generate a fix for every task that extends Javadoc. The fix task will be executed after the respective Javadoc task.

What does this do?

Imagine you have the following code, using jetbrains annotations (not annotations-java5):

import org.jetbrains.annotations.NotNull;

public class PlaceholderAPIUtils {

    /**
     * Applies PlaceholderAPI placeholders to a list of strings
     *
     * @param strings List of strings to apply placeholders to
     * @param player  Player to apply placeholders for
     * @return Unmodifiable list of strings with placeholders applied
     */
    @Contract(pure = true, value = "_, _ -> new")
    @NotNull
    public static List<@NotNull String> apply(@NotNull List<@NotNull String> strings, @Nullable OfflinePlayer player) {
        // ...
    }
}

If you generate javadocs, the annotations appear twice in the output:

img_2.png

Using the plugin, the doubled annotations are removed from the javadoc output:

img_1.png

You can also optionally set newLineOnMethodParameters to false, if you don't want to have a newline between annotations and method parameters:

img.png

Configuration

tasks.withType<FixJavadoc>().configureEach {

    // Whether to keep a newline between annotation and method parameter (see screenshots above), default: true
    newLineOnMethodParameters.set(true)

    // Whether to keep the original, unfixed docs in a folder called "javadoc-original", default: false
    keepOriginal.set(false)
}