Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate source files and compile them with gradle

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?

like image 408
Binil Thomas Avatar asked Feb 17 '11 05:02

Binil Thomas


People also ask

How do you create a source in Gradle?

You can achieve that by using the task or task provider as srcDir directly. It is almost always a sign of antipattern if you configure paths manually except for inputs / outputs of tasks.

Does Gradle compile?

Gradle is not equivalent to the compiler. Compilers primarily meant for translating the high-level language(i.e. java ) into machine code or other intermediate code representation like bytecode . wheres Gradle is a build system that packages the code for you and makes it ready for compilation.

What is source set in Gradle?

Gradle has the concept of source sets for where your code and test sources live. Some Gradle plugins come with default source sets, for example the Java plugin has a "main" source set where the default location is src/main/java .


1 Answers

You may try adding the path to the generated sources like this:

sourceSets {
    main {
        java {
            srcDir '<path to generatedJava>'
        }
    }
}
like image 99
c_maker Avatar answered Oct 19 '22 22:10

c_maker