How to generate javadoc in an Android project with JDK 11

Viewed 443

My setup:

  • Android Gradle Plugin 3.6.1
  • Gradle 6.2.1
  • JDK 11

I have a working configuration for building Javadoc using JDK 8. It looks like this (based on https://www.stkent.com/2016/02/05/adventures-with-javadocs-part-2.html):

tasks.withType(Javadoc) {
    options.addStringOption('Xdoclint:none', '-quiet')
    options.addStringOption('encoding', 'UTF-8')
    options.addStringOption('charSet', 'UTF-8')
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    from javadoc.destinationDir
    archiveClassifier.set('javadoc')
}

As commented in the article there is a large number of warnings about classes, etc. When using JDK 11 these warnings are now errors. And even if ignoring the errors I can see that the javadoc is not generated properly. Previously it included HTML with all the packages/classes but with JDK 11 there is only a metadata folder with a MANIFEST.MF file (contains: "Manifest-Version: 1.0").

What could be the cause for this changed behavior?

Update: Upon request in the comments I have added an example of the type of errors I get (as I mentioned, this type of errors is in the referenced article but in JDK8 they are just warnings):

 symbol:   class NonNull
  location: package androidx.annotation
/builds/myproject/src/main/java/com/mycompany/package/Bar.java:7: error: package com.mycompany.package does not exist
import com.mycompany.package.Foo;

FAILURE: Build failed with an exception.
1 Answers

This is solved adding --ignore-source-errors option to the javadoc.

For that you should add inside your javadoc task the following line:

options.addBooleanOption('-ignore-source-errors', true)
Related