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>'
        }
    }
}
Share:
13,726

Related videos on Youtube

Binil Thomas
Author by

Binil Thomas

Updated on August 05, 2020

Comments

  • Binil Thomas
    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 in src/main/java during compileJava?

  • Hans Westerbeek
    Hans Westerbeek almost 12 years
    eg sourceSets.main.java.srcDir '<path to generatedJava>'
  • Casey Watson
    Casey Watson almost 11 years
    You can also add multiples via srcDirs 'build/generated-src/java', 'src/main/java'
  • will
    will over 7 years
    I 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?

Related