Problem defining multiple source directories for a java project


I have a project that makes use of an annotation to generate java source code (to those who are curious, its a GWT-Platform annotation – @GenDispatch). I store those generated sources to the src/gen/java directory. The rest of the non-autogenerated sources are in src/main/java.

Here’s how I build the project: 1. compile the project with the compile arg: “-s src/gen/java” to generate the source code. 2. compile the project with compile arg: “-proc:none” to disable source generation by the annotation. The idea is just to compile the code generated in step 1 and the code in src/main/java

Step 1 above finishes without errors. The problem comes in step 2. I get a “cannot find symbol” compile error pertaining to the java source code generated in step 1.

Here’s the pertinent snippet from my build.gradle file:

sourceCompatibility = 1.6

sourceSets {

main {

java {



gen {

java {

srcDir ‘src/main/gen’


} }

compileGenJava {

configure(options) {

compilerArgs = [’-s’, ‘src/main/gen’]


destinationDir = sourceSets.main.classesDir }

compileJava {

configure(options) {

compilerArgs = [’-proc:none’]


source = [sourceSets.gen.allJava.srcDirs, sourceSets.main.allJava.srcDirs] }

compileJava.dependsOn compileGenJava

Any idea what’s wrong with this?


Why do you want to separate the source generation from compilation? Why not let the compiler generate the source and compile everything in one pass?