How to integrate generated sources into IntelliJ IDEA when using Gradle?

I am currently using JavaCC (with the JavaCC gradle plugin from here ) to generate part of my source code. The rest of the project depends on this code. If I import the project into IDEA or clean up the project, then I will get errors because the classes were not found. However, creating a project does work.

Is it possible to modify the gradle file so that IntelliJ (and possibly other editors too) know to generate these sources before parsing the code?

The generated code is stored in src / gen / java /, and the location of the generated code becomes known through:

sourceSets { gen { java { srcDir 'src/gen/java' } } } 

Since IntelliJ is building a project, I thought the easiest way:

 compileJava.dependsOn <generateSourcesTask> 

But adding this to the gradle file has no effect (perhaps because the JavaCC plugin does this already).

+5
source share
1 answer

Have you tried adding the source of the generated sources to main? Like this:

 sourceSets { main { java { srcDirs = ["src/main/java", "src/gen/java"] } } } 

It works for me with:

 compileJava.dependsOn('generateSourcesTask') 
+1
source

All Articles