[Gradle] Generate Javadoc including JavaScript in Java 1.8.0_121 or later

This is for those who have set JavaScript in Gradle's javadoc.options.bottom etc.

In Java 1.8.0_121, the javadoc command no longer allows JavaScript by default. http://www.oracle.com/technetwork/java/javase/8u121-relnotes-3315208.html

The javadoc tool will now reject any occurrences of JavaScript code in the javadoc documentation comments and command-line options, unless the command-line option, --allow-script-in-comments is specified.

I get an error when I run the javadoc task.

$ ./gradlew javadoc
[snip]
:javadoc
javadoc: error - Argument for -bottom contains JavaScript.
Use --allow-script-in-comments to allow use of JavaScript.
1 error
:javadoc FAILED

FAILURE: Build failed with an exception.

To enable JavaScript, add the --allow-script-in-comments option as described in the error message above.

build.gradle


javadoc.options {
    def v = JavaVersion.current()
    def g = System.properties['java.version'] =~ /\d+/
    addBooleanOption '-allow-script-in-comments', v.java9Compatible || v.majorVersion == '8' && g.size() == 4 && ((g[2] as int) > 0 || (g[3] as int) >= 121)
}

For the first argument of ʻaddBooleanOption, specify the option without the leading-. In the second argument, specify the boolean` value of whether to set the option. If you specify this option in a Java environment of 1.8.0_121 or earlier, an error will occur when executing the javadoc task, so the Java version is used to determine whether to set the option.

that's all.

reference

Gradle issue https://github.com/gradle/gradle/issues/1393 Implementation of javadoc.options.addBooleanOption https://github.com/gradle/gradle/blob/master/subprojects/language-java/src/main/java/org/gradle/external/javadoc/CoreJavadocOptions.java https://github.com/gradle/gradle/blob/master/subprojects/language-java/src/main/java/org/gradle/external/javadoc/internal/JavadocOptionFile.java https://github.com/gradle/gradle/blob/master/subprojects/language-java/src/main/java/org/gradle/external/javadoc/internal/BooleanJavadocOptionFileOption.java

Recommended Posts

[Gradle] Generate Javadoc including JavaScript in Java 1.8.0_121 or later
Try calling JavaScript in Java
Do HelloWorld in Java / IntelliJ / Gradle
Java, JavaScript, C # (difference in assignment)
Generate CloudStack API URL in Java
Hello world in Java and Gradle
(Limited to Java 7 or later) I want you to compare objects in Objects.equals
Call Java method from JavaScript executed in Java
Shortcut to automatically generate javadoc in IntelliJ
Using JavaScript from Java in Rhino 2021 version
How to remote debug Java 9 or later
Use "Rhino" which runs JavaScript in Java
Generate DB documentation using SchemaSpy in Gradle
[Java 7 or later] Prevent temporary file deletion omissions
NullPointerException countermeasure example (Optional) for Java 8 or later
[Gradle] Build operations often performed in Java projects
Static code analysis with Checkstyle in Java + Gradle
Generate normal distribution / lognormal distribution random numbers in Java
Differences in writing Java, C # and Javascript classes
Java tips-Create a Spring Boot project in Gradle
Generate OffsetDateTime from Clock and LocalDateTime in Java