Skip to content

Commit 9ef4101

Browse files
committed
exclude pre-packaged proto files from the build
This fixes #145. The Authzed API uses a couple of third-party proto definitions. After change #141 all of those third-party proto files were copied into the source folder and compiled as Java classes into the final JAR. This led to duplicated classes being on the classpath, e.g. com.google.rpc.Status which was now packed inside `com.authzed.api:authzed` and `com.google.api.grpc:proto-google-common-protos`. This makes dependency management very hard. Fortunately, most of the third-party protos come pre-compiled and pre-packaged with their own JAR files, available on Maven Central. They can simply be pulled in as compile-time dependency. The only exception is the grpc-gateway, where we have to copy the protos similar to the original approach. Signed-off-by: André Menneken <[email protected]>
1 parent 02940a6 commit 9ef4101

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,23 @@ dependencies {
106106
implementation "io.grpc:grpc-stub:${grpcVersion}"
107107
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
108108
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
109+
110+
implementation "com.google.api.grpc:proto-google-common-protos:2.61.3"
111+
implementation("build.buf:protovalidate:1.0.0")
112+
// In the future this can probably be removed in favor of "protovalidate"
113+
// See https://buf.build/blog/protoc-gen-validate-v1-and-v2
114+
implementation("build.buf.protoc-gen-validate:pgv-java-stub:1.2.1")
115+
}
116+
117+
// There is no pre-packaged JAR available that contains the gRPC Gateway proto files
118+
task gatewayProtos(type: Exec) {
119+
mkdir bufDir
120+
commandLine("buf", "export", "--exclude-imports", "buf.build/grpc-ecosystem/grpc-gateway", "-o", bufDir)
109121
}
110122

111123
task authzedProtos(type: Exec) {
112-
commandLine("buf", "export", "buf.build/authzed/api:${authzedProtoCommit}", "-o", bufDir)
124+
dependsOn gatewayProtos
125+
commandLine("buf", "export", "--exclude-imports", "buf.build/authzed/api:${authzedProtoCommit}", "-o", bufDir)
113126
}
114127

115128
protobuf {

0 commit comments

Comments
 (0)