Repository: mockito/mockito
Issue: Javadoc generation fails with jdk1.8.0_121
Labels: java-8
continuous integration

When I set the jdk to jdk1.8.0_121 the build fails javadoc error. 

Full log including steps to reproduce:

```
~/mockito/src$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/
~/mockito/src$ ./gradlew javadoc -i


...

javadoc: error - Argument for -top contains JavaScript.
Use --allow-script-in-comments to allow use of JavaScript.
1 error
100 warnings
Problems generating Javadoc.

...

:javadoc FAILED
:javadoc (Thread[Task worker,5,main]) completed. Took 1.936 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':javadoc'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/Users/sfaber/mockito/src/build/tmp/javadoc/javadoc.options'

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED
```

Issue comments:
I tried to add in previous Open JDK 8 (102) but the option is not recognized

```
option.addStringOption('--allow-script-in-comments')
option.addStringOption('-allow-script-in-comments')
option.addStringOption('allow-script-in-comments')
```

I'll try later with the same JDK (121)
Could it be related to #787 ?
I will also take another look at the service-worker thing, as it does not appear to work with javadoc.io. If I can't fix it (after exams :wink: ) then I will simply revert it.
;)

Contiuous improvements
From the release notes: 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.
> 
> With the --allow-script-in-comments option, the javadoc tool will preserve JavaScript code in documentation comments and command-line options. An error will be given by the javadoc tool if JavaScript code is found and the command-line option is not set.
> JDK-8138725 (not public)

Pull request review comments:
Thank you for fixing the problem and documenting it diligently!

Patch that resolved the issue:
diff --git a/gradle/mockito-core/javadoc.gradle b/gradle/mockito-core/javadoc.gradle
index 5bb5203299..a8d4be36ec 100644
--- a/gradle/mockito-core/javadoc.gradle
+++ b/gradle/mockito-core/javadoc.gradle
@@ -66,8 +66,18 @@ javadoc {
     """.replaceAll(/\r|\n|[ ]{8}/, ""))
     if (JavaVersion.current().isJava8Compatible()) {
         options.addStringOption('Xdoclint:none', '-quiet')
+
+        def minorVersion = System.getProperty("java.version") =~ /1.8.0_(.*)/
+
+        // Since JDK 8 version 121 scripts are not allowed in comments. However,
+        // earlier version throw an error if an unknown option is passed.
+        // Therefore only add this option if the JDK is actually correct.
+        if (minorVersion.size() > 0 && Integer.valueOf(minorVersion[0][1]) >= 121) {
+            options.addBooleanOption('-allow-script-in-comments', true)
+        }
     }
 
+
     doLast {
         copy {
             from "src/javadoc"


Test patch: