I've created custom source set in Gradle project to keep all generated code:
sourceSets {
generated {
java {
srcDir 'src/generated/java'
}
resources {
srcDir 'src/generated/resources'
}
}
}
I want to make the result of this source set's code compilation available at compile and run time for main
and test
source sets.
What's the right semantic way to do it in Gradle?
UPDATE:
As suggested here: How do I add a new sourceset to Gradle? doesn't work for me, I still get java.lang.ClassNotFoundException
when I launch my app (though compilation and unit tests run fine). Here is what I tried:
sourceSets {
main {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
test {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
1.1 What is a Gradle SourceSet ? A SourceSet is a collection of java source files and additional resource files that are compiled and assembled together to be executed. The main idea of sourcesets is to group files with a common meaning for the project, with no need of separate them in another project.
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
main. runtimeClasspath' contains the compiled classes of the source set, and task autowiring automatically adds the necessary task dependencies. Maybe you want 'sourceSets. main. compileClasspath'.
compileOnly dependencies are available while compiling but not when running them. This is equivalent to the provided scope in maven. It means that everyone who wants to execute it needs to supply a library with all classes of the CompileOnly library.
sourceSets {
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
}
Same for the test
source set.
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