1

In an Android library project I use Gradle script to generate Javadocs:

task androidJavadocs(type: Exec, dependsOn: buildJavadocsClasspath) {
  doFirst {

    executable = 'javadoc'

    args = [
        '-classpath', javadocsClasspath,
        '-sourcepath', './src/main/java',
        '-subpackages', 'com.example.myproject',
        '-d', javadocsDestinationDir,
        '-exclude', 'com.example.myproject.internal',
        '-doctitle', project.getName() + " " + VERSION_NAME + " API",
        '-windowtitle', POM_NAME + " API",
        '-link', "http://docs.oracle.com/javase/8/docs/api/",
        '-Xdoclint:none',
        '-quiet'
    ]
  }
}

The problem is that Javadoc returns warnings (Java 8) or errors (Java 11) when generating javadocs for classes that reference autogenerated classes like BuildConfig or DaggerMyClientComponent

./src/main/java/com/example/myproject/MyClient.java:13: error: cannot find symbol
import com.example.myproject.internal.DaggerMyClientComponent;
                                              ^
  symbol:   class DaggerMyClientComponent
  location: package com.example.myproject.internal
./src/main/java/com/example/myproject/internal/storage/client/SdkVersionStorage.java:9: error: cannot find symbol
import com.example.myproject.BuildConfig;
                                     ^
  symbol:   class BuildConfig
  location: package com.example.myproject
./src/main/java/com/example/myproject/internal/utils/UserAgentHeader.java:8: error: cannot find symbol
import com.example.myproject.BuildConfig;
                                     ^
  symbol:   class BuildConfig
  location: package com.example.myproject

One thing that I don't understand is that two errors come from internal classes that are already excluded from javadoc with the "exclude" argument.

On top of that, I don't see an option to fix or suppress those errors. Adding an exclude rule like com.example.myproject.internal.DaggerMyClientComponent doesn't work.

Using Android Studio to generate Javadocs is not an option, I need to use a script that can be used in CI (Bitrise).

LR89
  • 397
  • 1
  • 4
  • 14
  • Did you have any luck with this? I am suffering the exact same problem. Receiving errors due to excluding my internal package – franmontiel Nov 15 '21 at 17:45

1 Answers1

2

You have two ways of solving this:

Option 1

Adding --ignore-source-errors to the javadoc command (I took this approach from this other answer)

For the ones using the javadoc gradle task they can add it this way:

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

Option 2

Or adding to the sourcepath the path to your BuildConfig.java file (in case you want to document it)

For the ones using the javadoc gradle task add it to the source attribute:

source = android.sourceSets.main.java.source + file('build/generated/source/buildConfig/release/your/package/BuildConfig.java').path
franmontiel
  • 1,860
  • 1
  • 16
  • 20