Gradle protobuf扩展源集,包括单个文件。

huangapple go评论78阅读模式
英文:

Gradle protobuf extension sourcesets with single files

问题

在我的应用程序中,我有一个包含多个 proto 定义的子模块,我使用以下方式添加它们:

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

是否可以针对源集中的单个文件而不是整个目录进行定位?
当我有一个文件依赖于同一目录中的另一个文件时,是否也可以实现这一点?

英文:

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?

答案1

得分: 1

无法在您的proto文件中包括/排除用于导入的文件。可以过滤用于代码生成的文件。

目前无法仅包括您希望的文件。这是因为protobuf-gradle-plugin已经使用了'include',而包括是累加的。您可能需要在protobuf-gradle-plugin存储库上提交一个问题。

但是,您仍然可以排除您不感兴趣的文件。排除是相对于源目录的,并适用于源目录集中的所有目录。

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

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"
        }
    }
}

huangapple
  • 本文由 发表于 2023年6月29日 23:28:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定