title: How do you add a source set to a Java project in gradle 2.1?
body: <p>How do you add a source set to a Java project in gradle 2.1?</p>
  
  <p>I've read the docs on the <a href="http://www.gradle.org/docs/current/userguide/java_plugin.html" rel="nofollow">Java Plugin</a> and <a href="http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSetOutput.html" rel="nofollow">SourceSetOutput</a> and a few other SO threads and I'm still struggling to figure out how it works.</p>
  
  <p>I created a simple build script to test my understanding. Based on Section 23.7.2, example 23.5 of the User Guide, it appears I can create a sourceSet by doing:</p>
  
  <pre><code>sourceSets {
     generated
  }
  </code></pre>
  
  <p>In section 23.4. Project layout seems to imply that this all I need to do because my source set follows the gradle convention. Code to be included in the source set is in <code>src/generated/java/packagename</code>. and will be automatically added to the classpath. Based on the symbol not found errors I'm getting from code that uses code defined in the generated source set, I assume that this incorrect and something else needs to be done. What do I need to do?</p>
  
  <p>Here's my setup:</p>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>apply plugin: 'java'
  apply plugin: 'application'
  
  mainClassName = "tester.Test"
  
  sourceSets {
      generated
  }
  </code></pre>
  
  <p><strong>File structure</strong></p>
  
  <pre><code>tester/
  ├── build
  │   ├── classes
  │   │   └── main
  │   ├── dependency-cache
  │   └── tmp
  │       └── compileJava
  ├── build.gradle
  └── src
      ├── generated
      │   └── java
      │       └── tester
      │           └── Boom.java
      └── main
          └── java
              └── tester
                  └── Test.java
  </code></pre>
  
  <p><strong>Boom.java</strong></p>
  
  <pre><code>package tester;
  
  class Boom {
     String sound;
  
     public Boom (String s){
        sound = s;
     }
  }
  </code></pre>
  
  <p><strong>Test.java</strong></p>
  
  <pre><code>package tester;
  
  class Test {
     public static void main(String[] args) {
        Boom b = new Boom("KABOOM");
  
        System.out.println("I've run");
        System.out.println(b.sound);
     }
  }
  </code></pre>