Reputation: 10016
The Gradle docs say that the default SourceSet, main
, is compiled and assembled into a Jar. I have a group of non-Java template files that I want to compile using a custom plugin. The SourceSet concept seems like a good way to keep all these template files organized, but I don't want Gradle to try to compile them as Java files. Is there a way to override the default SourceSet behaviour so that I can tell Gradle exactly what I want done to the files in the SourceSet? If not, is there another Gradle construct I can use to group together non-Java source files into logical units?
Upvotes: 0
Views: 1084
Reputation: 10898
Here's an example how to keep non-java files organized and how to process them:
apply plugin: "java"
sourceSets {
template {
resources {
srcDir 'src/template'
include '**/*'
}
}
}
processTemplateResources {
doLast {
println sourceSets.template.output.classesDir
FileTree tree = fileTree(dir: sourceSets.template.output.resourcesDir)
tree.forEach {
println it
}
}
}
jar {
from sourceSets.main.output
from sourceSets.template.output
}
I've defined a new resources-only source set. This automatically adds the process resources task which copies the resources to the output directory. You can then process them there.
In the end, simply add them to your jar if needed.
Upvotes: 3