4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Gradle] Java 1.8.0_121以降でJavaScriptを含むJavadocを生成する

Posted at

Gradleのjavadoc.options.bottom等でJavaScriptを設定している方向けの内容です。

Java 1.8.0_121で、javadocコマンドはデフォルトでJavaScriptを許可しないようになりました。
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.

javadocタスクを実行するとエラーになります。

$ ./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.

JavaScriptを有効にするには、上記エラーメッセージに記載されているように--allow-script-in-commentsオプションを追加します。

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)
}

addBooleanOptionの第一引数には、オプションから先頭の-を除いたものを指定します。
第二引数には、オプションを設定するかどうかのboolean値を指定します。
1.8.0_121以前のJava環境で当該オプションを指定すると、javadocタスク実行時にエラーが発生するので、Javaのバージョンを見てオプションを設定するかどうかを判断しています。

以上です。

参考

Gradleのissue
https://github.com/gradle/gradle/issues/1393
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

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?