title: Javadoc generation "error package does not exist" in multi module project
body: <p>I need to upload my libraries(multi-module project) into sonatype repository through Bintray. So that I need to generate the Javadoc individually for each module.</p>
  
  <p>First I faced the problems in these similar questions</p>
  
  <p><a href="https://stackoverflow.com/questions/34571371/android-studio-javadoc-cannot-find-symbol">Android Studio Javadoc: Cannot find symbol</a></p>
  
  <p><a href="https://stackoverflow.com/questions/28943231/gradle-javadoc-fails-with-error-package-does-not-exist">Gradle Javadoc fails with “error: package … does not exist”</a></p>
  
  <p>From the solution in the first <a href="https://stackoverflow.com/a/34572606/5134215">question</a>, I can resolve the classes that I have used from third party libraries(retrofit2, gson)  and <code>@NonNull</code> annotations errors.</p>
  
  <p>But in my case one of my modules(<code>Lib2</code>) depends on another module(<code>Lib1</code>).</p>
  
  <p>When generating the Javadoc for <code>Lib2</code> module, its warning <code>package does not exist</code> &amp; <code>cannot find symbol</code> for the classes of another module(<code>Lib1</code>).</p>
  
  <p>And both modules reports <code>package does not exist</code> error for android support &amp; design libraries.</p>
  
  <p>And Every <code>import &lt;packagename&gt;.R;</code> reports <code>cannot find symbol</code></p>
  
  <p>My Javadoc generating task</p>
  
  <pre><code>task androidJavadocs(type: Javadoc) {
        source = android.sourceSets.main.java.source
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
        ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath += files(ext.androidJar)
        project.android.libraryVariants.all { variant -&gt;
          classpath += files(variant.javaCompile.classpath.files)
        }
  }
  </code></pre>
  
  <p>dependencies in Lib1 <code>build.gradle</code></p>
  
  <pre><code>compile rootProject.appcompat
  compile rootProject.design
  compile rootProject.retrofit2
  compile rootProject.support
  compile rootProject.gsonConverter
  compile rootProject.httpLogInterceptor
  compile rootProject.universalImageLoader
  </code></pre>
  
  <p>dependencies in Lib2 <code>build.gradle</code></p>
  
  <pre><code>compile project(':core')
  compile rootProject.appcompat
  compile rootProject.design
  compile rootProject.retrofit2
  compile rootProject.support
  compile rootProject.cardview
  </code></pre>
  
  <p>I have tried </p>
  
  <pre><code>task androidJavadocs(type: Javadoc) {
      source = android.sourceSets.main.java.srcDirs
      classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
  }
  
  afterEvaluate {
      androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
  }
  </code></pre>
  
  <p>My entire <code>gradle-mvn-push.gradle</code></p>
  
  <pre><code>apply plugin: 'maven'
  apply plugin: 'com.jfrog.bintray'
  // Declaring variables
  
  afterEvaluate {  project -&gt;
    bintray {
      user = bin_user
      key = bin_key
      configurations = ['archives']
      publish = true
      dryRun = false
      pkg {
        repo = REPO
        name = POM_ARTIFACT_ID
        userOrg = USER_ORG
        desc = POM_DESCRIPTION
        websiteUrl = POM_URL
        vcsUrl = GIT_URL
        licenses = ['Apache-2.0']
        version {
          name = VERSION_NAME
          vcsTag = VERSION_NAME
          gpg {
            sign = true
            try {
              passphrase = PASS_PHRASE
            } catch (Exception ignored) {
              println 'Failed to find credentials. GPG sign disabled'
            }
          }
        }
      }
    }
  
    if (project.getPlugins().hasPlugin('com.android.application') ||
            project.getPlugins().hasPlugin('com.android.library')) {
      task install(type: Upload, dependsOn: assemble) {
        repositories.mavenInstaller {
          configuration = configurations.archives
  
          pom.groupId = GROUP
          pom.artifactId = POM_ARTIFACT_ID
          pom.version = VERSION_NAME
  
          pom.project {
            name POM_NAME
            packaging POM_PACKAGING
            description POM_DESCRIPTION
            url POM_URL
  
            scm {
              url POM_SCM_URL
              connection POM_SCM_CONNECTION
              developerConnection POM_SCM_DEV_CONNECTION
            }
  
            licenses {
              license {
                name POM_LICENCE_NAME
                url POM_LICENCE_URL
                distribution POM_LICENCE_DIST
              }
            }
  
            developers {
              developer {
                id pom_developer_id
                name pom_developer_name
              }
            }
  
          }
  
          pom.withXml {
            def dependenciesNode = asNode().appendNode('dependencies')
  
            //Iterate over the compile dependencies (we don't want the test ones), adding a &lt;dependency&gt; node for each
            configurations.compile.allDependencies.each {
              def dependencyNode = dependenciesNode.appendNode('dependency')
              dependencyNode.appendNode('groupId', it.group)
              dependencyNode.appendNode('artifactId', it.name)
              dependencyNode.appendNode('version', it.version)
            }
          }
        }
      }
  
      task androidJavadocs(type: Javadoc) {
        source = android.sourceSets.main.java.source
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
        ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath += files(ext.androidJar)
        project.android.libraryVariants.all { variant -&gt;
          classpath += files(variant.javaCompile.classpath.files)
        }
      }
  
      task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
        classifier = 'javadoc'
        from androidJavadocs.destinationDir
      }
  
      task androidSourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.source
      }
  
  
    } else {
      install {
        repositories.mavenInstaller {
          pom.groupId = GROUP
          pom.artifactId = POM_ARTIFACT_ID
          pom.version = VERSION_NAME
  
          pom.project {
            name POM_NAME
            packaging POM_PACKAGING
            description POM_DESCRIPTION
            url POM_URL
  
            scm {
              url POM_SCM_URL
              connection POM_SCM_CONNECTION
              developerConnection POM_SCM_DEV_CONNECTION
            }
  
            licenses {
              license {
                name POM_LICENCE_NAME
                url POM_LICENCE_URL
                distribution POM_LICENCE_DIST
              }
            }
  
            developers {
              developer {
                id POM_DEVELOPER_ID
                name POM_DEVELOPER_NAME
              }
            }
          }
        }
      }
  
      task sourcesJar(type: Jar, dependsOn:classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
      }
  
      task javadocJar(type: Jar, dependsOn:javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
      }
    }
  
    if (JavaVersion.current().isJava8Compatible()) {
      allprojects {
        tasks.withType(Javadoc) {
          options.addStringOption('Xdoclint:none', '-quiet')
        }
      }
    }
  
    artifacts {
      if (project.getPlugins().hasPlugin('com.android.application') ||
              project.getPlugins().hasPlugin('com.android.library')) {
        archives androidSourcesJar
        archives androidJavadocsJar
      } else {
        archives sourcesJar
        archives javadocJar
      }
    }
  }
  </code></pre>