Avoiding so many deps will allow us to upgrade the protos without being forced to upgrade to protobuf-java 4.x. It also removes the remaining non-bzlmod dependencies. It'd be really easy to get this wrong, so we do two things 1) mirror the gradle configuration as much as possible, as that sees a lot of testing, and 2) run the fake control plane with the _results_ of jarjar. There's lots of classes that we could mess up, but that at least kicks the tires. XdsTestUtils.buildRouteConfiguration() was moved to ControlPlaneRule to stop the unnecessary circular dependency between the classes and to avoid the many dependencies of XdsTestUtils. I'm totally hacking java_grpc_library to improve the dependency situation. Long-term, I think we will stop building Java libraries with Bazel and require users to rely entirely on Maven Central. That seems to be the direction Bazel is going and it will greatly simplify the problems we've seen with protobuf having a single repository for many languages. So while the hack isn't too bad, I hope we won't have to live with it long-term. |
||
|---|---|---|
| .. | ||
| src | ||
| BUILD.bazel | ||
| README.md | ||
| build.gradle | ||
| check-artifact.sh | ||
README.md
gRPC Java Codegen Plugin for Protobuf Compiler
This generates the Java interfaces out of the service definition from a
.proto file. It works with the Protobuf Compiler (protoc).
Normally you don't need to compile the codegen by yourself, since pre-compiled binaries for common platforms are available on Maven Central:
- Navigate to https://mvnrepository.com/artifact/io.grpc/protoc-gen-grpc-java
- Click into a version
- Click "Files"
However, if the pre-compiled binaries are not compatible with your system, you may want to build your own codegen.
Compiling and testing the codegen
Set up your system as described in COMPILING.md.
Then change to the compiler directory:
$ cd $GRPC_JAVA_ROOT/compiler
To compile the plugin:
$ ../gradlew java_pluginExecutable
To test the plugin with the compiler:
$ ../gradlew test
You will see a PASS if the test succeeds.
To compile a proto file and generate Java interfaces out of the service definitions:
$ protoc --plugin=protoc-gen-grpc-java=build/exe/java_plugin/protoc-gen-grpc-java \
--grpc-java_out="$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
To generate Java interfaces with protobuf lite:
$ protoc --plugin=protoc-gen-grpc-java=build/exe/java_plugin/protoc-gen-grpc-java \
--grpc-java_out=lite:"$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
Installing the codegen to Maven local repository
This will compile a codegen and put it under your ~/.m2/repository. This
will make it available to any build tool that pulls codegens from Maven
repositories.
$ ../gradlew publishToMavenLocal
Creating a release of gRPC Java
Please follow the instructions in RELEASING.md under the root directory for
details on how to create a new release.