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
?
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.
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.
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 .
You may try adding the path to the generated sources like this:
sourceSets {
main {
java {
srcDir '<path to generatedJava>'
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With