How to generate source files and compile them with gradle
13,726
You may try adding the path to the generated sources like this:
sourceSets {
main {
java {
srcDir '<path to generatedJava>'
}
}
}
Related videos on Youtube
Author by
Binil Thomas
Updated on August 05, 2020Comments
-
Binil Thomas over 3 years
I have a gradle build script similar to:
apply plugin: 'war' task genSources << { // here I generate some java files } // making sure that source files are generated // before compilation compileJava.dependsOn(genSources)
How can I make the files generated in
genSources
compile along with files insrc/main/java
duringcompileJava
? -
Hans Westerbeek almost 12 yearseg sourceSets.main.java.srcDir '<path to generatedJava>'
-
Casey Watson almost 11 yearsYou can also add multiples via
srcDirs 'build/generated-src/java', 'src/main/java'
-
will over 7 yearsI found this helped me get the generated files compiled OK from a
generated/java/
location. But for some reason the task to generate the JAXB classes from XSD files does NOT fire even when it is a dependency of the compile in genSources. I still need to manually enter:gradle xjc
separate, and before I Build. Any ideas?