title: Gradle Javadoc fails with "error: package ... does not exist"
body: <p>Our Gradle build script fails when building Javadocs for Android Studio project for a library we develop, with errors like:</p>
  
  <blockquote>
    <p><strong>/MY_LOCAL_PATH/MyClass.java:5: error: package com.google.gson does not exist
    import com.google.gson.Gson;</strong></p>
  </blockquote>
  
  <p><strong>Details:</strong></p>
  
  <p>We are building an Android library with <code>Gradle</code>, and want to build the <code>Javadocs</code> for it.</p>
  
  <p>The Android Studio project is configured to require a <code>Maven dependency</code> for <code>GSON</code>, although I'm guessing it would happen with every dependency whose <code>lib</code> file is not provided explicitly.</p>
  
  <p>One of our classes, of course, <code>imports com.google.gson.</code></p>
  
  <p>Here is our Gradle script:</p>
  
  <pre><code>buildscript {
      repositories {
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:1.1.0'
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  
  allprojects {
      repositories {
          jcenter()
      }
  }
  
  apply plugin: 'com.android.library'
  
  android {
      compileSdkVersion 19
      buildToolsVersion '21.1.2'
      defaultConfig {
          minSdkVersion 19
          targetSdkVersion 19
          versionCode 8000
          versionName "0.8.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      productFlavors {
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.google.code.gson:gson:2.2.4'
  }
  </code></pre>
  
  <p>And the task that's expected to build the docs (based on <a href="https://stackoverflow.com/questions/17033878/generate-javadocs-with-android-gradle-plugin">this question</a>):</p>
  
  <pre><code>task generateJavaDocs(type:Javadoc) {
    source = 'src/main/java/com'
  
    ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    classpath = files(source) + files(ext.androidJar)
  
    options.memberLevel = JavadocMemberLevel.PUBLIC
    include '**/*.java'
    exclude '**/BuildConfig.java'
    exclude '**/R.java'
  }
  </code></pre>
  
  <p>When reaching this task, Gradle fails with these errors:</p>
  
  <blockquote>
    <p><strong>/MY_LOCAL_PATH/MyClass.java:5: error:</strong> package com.google.gson does not exist
        import com.google.gson.Gson;</p>
    
    <p><strong>/MY_LOCAL_PATH/MyClass.java:6: error:</strong> package com.google.gson does not exist
        import com.google.gson.JsonParseException;</p>
    
    <p><strong>/MY_LOCAL_PATH/MyClass.java:7: error:</strong> package com.google.gson does not exist
        import com.google.gson.JsonSyntaxException;</p>
    
    <p><strong>/MY_LOCAL_PATH/MyClass.java:8: error:</strong> package com.google.gson.reflect does not exist
      import com.google.gson.reflect.TypeToken;</p>
  </blockquote>
  
  <p>Anyone has a thoughts on how to solve this?</p>
  
  <p>Thanks!</p>