I am trying to generate file descriptors using protobuf-gradle-plugin:
protobuf {
    // Configure the protoc executable
    protoc {
        artifact = "com.google.protobuf:protoc:$dependencyVersions.protobuf"
        generatedFilesBaseDir = "$projectDir/src/generated-sources"
    }
    generateProtoTasks {
        all().each { task ->
            task.generateDescriptorSet = true
            task.descriptorSetOptions.path = "$projectDir/src/generated-sources/descriptors/{$task.sourceSet.name}.dsc"
        }
    }
}
sourceSets {
    main {
        proto {
            srcDir 'src/main/proto'
            exclude 'google/*'
        }
    }
}
But this only generates one descriptor file:{main}.desc. Am I only supposed to have one descriptor file for many proto files? If not, how would I go about generating a separate descriptor file for each proto file using the plugin?
I thought that there would be a separate file for each proto, but it appears we can only generate one large file descriptor for all protos: descriptors.dsc. 
In hindsight, multiple descriptor files aren't really necessary because you can use this one file pretty easily in Java:
final FileInputStream fileInputStream = new FileInputStream("directory/descriptors.dsc");
final DescriptorProtos.FileDescriptorSet descriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(fileInputStream);
for (DescriptorProtos.FileDescriptorProto fileDescriptor : descriptorSet.getFileList()) {
     // Do as you wish with fileDescriptor
}
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