title: Get compiled .class output directory in Android Gradle task
body: <p>I'm creating a Gradle task for my Android project that needs to know the path to the compiled <code>.class</code> files. How can I get this path? I've found suggestions (<a href="https://stackoverflow.com/a/26667774/3004881">here</a> and <a href="https://stackoverflow.com/q/19927627/3004881">here</a>; also see <a href="https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSet.html" rel="noreferrer">the Gradle docs for <code>SourceSet</code></a>) that <code>sourceSets.main.output.classDir</code> will give me this path, but when I try to use it, I get the error</p>
  
  <blockquote>
    <p>Could not find property <code>'output'</code> on source set <code>main</code>.</p>
  </blockquote>
  
  <p>This happens even when I create a new, minimal project, with the following <code>build.gradle</code>:</p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:1.5.0'
      }
  }
  apply plugin: 'android'
  android {
      compileSdkVersion 22
      buildToolsVersion "20.0.0"
  
      task printClassesDir &lt;&lt; {
          println sourceSets.main.output.classesDir
      }
  }
  </code></pre>
  
  <p>This minimal project builds fine, but will give that error if I run the task <code>printClassesDir</code>. How can I get the <code>.class</code> file output directory in my task?</p>
  
  <hr>
  
  <p>I've also tried the suggestion of <code>&lt;build variant&gt;.javaCompile.classpath</code> from <a href="https://stackoverflow.com/a/28224687/3004881">this answer to another question</a>. I was able to access this property with</p>
  
  <pre><code>applicationVariants.find{it.name == 'debug'}.javaCompile.classpath
  </code></pre>
  
  <p>but this file collection is empty.</p>
  
  <hr>
  
  <p>For reference, here are the other files for my minimal project:</p>
  
  <h3><code>src/main/AndroidManifest.xml</code></h3>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="a.b"&gt;
    &lt;uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="22" /&gt;
    &lt;application&gt;
      &lt;activity android:name=".Main"&gt;
        &lt;intent-filter&gt;
      &lt;action android:name="android.intent.action.MAIN" /&gt;
      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
      &lt;/activity&gt;
    &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <h3><code>src/main/java/a/b/Main.java</code></h3>
  
  <pre><code>package a.b;
  import android.app.Activity;
  public class Main extends Activity { }
  </code></pre>