How to add a folder to an android project sourceset from a gradle plugin
<p>I'm writing a plugin for gradle, to generate some classes for Android projects. </p>

<p>I generate those classes in the projects <code>src/gen/java</code> folder, as I don't want them to be mixed with real source code. </p>

<p>From the project's <code>build.gradle</code> config, I can add this to make the build tools see the generated classes : </p>

<pre><code>android {
    sourceSets {
        main {
            java {
                srcDir 'src/gen/java'
            }
        }
    }
} 
</code></pre>

<p>The problem is that I want my plugin to set this automatically. From my plugin I tried the followings : </p>

<p>public class MyPlugin implements Plugin {</p>

<pre><code>@Override
public void apply(Project project) {
    // ... 
    // TEST 1 : doesnt work
    project.android.sourceSets.main.java.srcDirs += "src/gen/java"

    // TEST 2 : doesnt work
    project.android.sourceSets {
        main {
            java {
                srcDir 'src/gen/java'
            }
        }
    }
}
</code></pre>

<p>}</p>

<p>Each time the plugin works, but the folder is still not seen by the compiler and it can't find the generated classes when compiling. Does any one know of another way to do this from the plugin ?</p>