gradleprotocol-bufferscode-generationsource-sets

Gradle protobuf extension sourcesets with single files


In my application I have a submodule with several proto definitions, I add them with:

sourceSets {
    main {
        proto {
            srcDirs "$projectDir/grpc/src/main/protobuf"
        }
    }
}

Is it possible to target the individual files in the sourcesets instead of the whole directory?
Is this also possible when I have one file depending on another one in the same directory?


Solution

  • It is not possible to include/exclude files used for imports within your proto files. It is possible to filter files for code generation.

    Currently it is not possible to include only the files you wish. This is because the protobuf-gradle-plugin is already using 'include' and includes are each additive. You may want to file an issue on the protobuf-gradle-plugin repository.

    But you can still exclude files you aren't interested in. Excludes are relative to the source directory and apply to all directories in the source directory set.

    sourceSets {
        main {
            proto {
                srcDirs "$projectDir/grpc/src/main/protobuf"
                exclude "example/foo/**"
                exclude "example/bar/baz.proto"
                exclude "**/feature_*.proto"
            }
        }
    }