In a multi-module code base
We have a code generation task that creates generated source code and some additional resource files and attaches them to the main sources of a specific module.
In another module I want to consume the additional resource files and consume them in some way.
I have looked at:
And tried to use this however I’m having trouble on the consumer side as the variant is the source project’s main resources which is simply a “dir”:
// consumer side build.gradle.kts
// Configuration to extract the resource files from the source project
val generated by configurations.dependencyScope("generated") {
isTransitive = false
}
val generatedResources by configurations.resolvable("generatedResources") {
extendsFrom(generated)
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.MAIN_SOURCES))
}
isTransitive = false // We're only interested in this module's generated resources
}
dependencies {
generated(project(":project_that_generates_code_and_resources"))
}
// Class that filters the Generated Code via JVM tool
@CacheableTask
abstract class FilterTask: JavaExec() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val inputFile: RegularFileProperty
@get:OutputFile
abstract val outputFile: RegularFileProperty
@get:Input
abstract val componentName: Property<String>
init {
mainClass.set("com.example.CustomFilterClass")
}
@TaskAction
override fun exec() {
args(mutableListOf(inputFile.asFile.get().path, outputFile.asFile.get().path, componentName.get())
super.exec()
}
}
// Actual usage of that task class:
val filterGenerated by tasks.registering(FilterTask::class) {
dependsOn(":project_that_generates_code_and_resources:generatorTask")
componentName.set("aComponent")
classpath = toolClasspath // not shown
// Need assistance here, is this the best approach?
inputFile.fileProvider(
project.provider {
// to access the generated resources - what's the best way?
}
)
outputFile = layout.buildDirectory.file("filtered-example.something")
}
As shown in the instance filterGenerated what’s the best way of safely getting access to the build/generated-sources/resources output from the fileProvider? These aren’t standard properties files, they’re essentially intermediate binary files created by the code generator.