Hello everyone, I’m facing a particular puzzle on ...
# plugin-development
j
Hello everyone, I’m facing a particular puzzle on writing my own Gradle task to process Android resources. My task should receive as input the source sets of the variant and then, after processing the files, it should save them in the build/generated folder and add the folder to the source set of the variant to be used by other tasks when building the app/library. The problem is a circular dependency since I need to listen to the source sets to understand if there are any changes there (input) and adding the output to the source set will trigger the input again, creating an endless loop. Is there a better way to achieve the expected behavior?
Copy code
val outputDir = project.layout.buildDirectory.dir(BUILD_FOLDER + it.name)

            val task =
                project.tasks.register(taskName, MyTask::class.java) { task ->
                    task.group = "my-custom-task"
                    task.source.set(it.sources.res?.all) // Input
                    task.destination.set(outputDir) // Output
                }

            // This will add the new folder to the sourceSet of the variant
            it.sources.res?.addGeneratedSourceDirectory(
                task,
                MyTask::destination
            )