Generated sources declaration / visibility


(François) #1

Hi,

I’m using an annotation processor.
After configuration the Java source files are generated inside an /src/generated/java directory.

If I execute a compileJava task, everything’s fine, the java classes consuming the generated sources compile fine ; but the IDE (idea in my case) didn’t detect the src/generated/java as a source folder.

My question is what is the best way to declare these generated source files ? So I have listed these solutions :

  1. declare a brand new source set named generated. But in the documentation, generated files are not the perfect match for a new sourcetset.
  2. add the src/generated/java dir to the main.java.srcDirs.
    sourceSets { main.java.srcDirs = ['/src/main/java', 'src/generated/java'] }
    That seems unnecessary because Gradle compileJava tasks works fine without that. Or is this a gradle bug ? Gradle automatically adds the generated sources to the classpath ?
  3. I can configure the Idea module as

idea {
module {
sourceDirs += file(‘src/generated/java’)
generatedSourceDirs += file(‘src/generated/java’)
}
}

thanks in advance