Fix gRPC auto-configuration when protobuf is used without gRPC#50827
Open
UjjwalChitransh wants to merge 1 commit into
Open
Fix gRPC auto-configuration when protobuf is used without gRPC#50827UjjwalChitransh wants to merge 1 commit into
UjjwalChitransh wants to merge 1 commit into
Conversation
ProtobufPluginAction now checks whether any io.grpc dependency is declared before configuring the protoc-gen-grpc-java plugin. Previously the plugin was always registered, causing Gradle to resolve io.grpc:protoc-gen-grpc-java:null for projects that use protobuf but not gRPC (fixes spring-projectsgh-50822). spring-boot-grpc-test has been removed from spring-boot-test-classic- modules. Including it with transitive=false left GrpcServerStartedEvent off the classpath while GrpcPortInfoApplicationContextInitializer still referenced it as a generic type parameter, triggering TypeNotPresentException during Spring's listener introspection (fixes spring-projectsgh-50825). Signed-off-by: Ujjwal Chitransh <ujjwalchitransh1@gmail.com>
52ee738 to
0e06bd5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two related regressions introduced in 4.1.0 around gRPC/protobuf:
gh-50822 —
Could not find io.grpc:protoc-gen-grpc-java:nullProtobufPluginActionunconditionally registered agrpcplugin in the Protobuf extension whenever thecom.google.protobufGradle plugin was detected. This caused Gradle to create aprotobufToolsLocator_grpcconfiguration and try to resolveio.grpc:protoc-gen-grpc-javawithout a version. The version-alignment resolution strategy substitutes the version from the runtime classpath, but when gRPC is not in the project at all, no version is found and Gradle reportsio.grpc:protoc-gen-grpc-java:null.gh-50825 —
TypeNotPresentException: Type GrpcServerStartedEvent not presentspring-boot-grpc-testwas added tospring-boot-test-classic-moduleswithtransitive = false. This put theGrpcPortInfoApplicationContextInitializerclass on the classpath but left its dependencyGrpcServerStartedEvent(fromspring-grpc) off the classpath. When Spring introspects application listeners at context startup it reads the generic type parameter ofApplicationListener<GrpcServerStartedEvent>via reflection, which throwsTypeNotPresentExceptionbecause the class is absent.Fix
ProtobufPluginAction— gRPC plugin configuration is now deferred toafterEvaluateand only applied when at least one dependency with groupio.grpcis declared in any project configuration. Projects that use protobuf but not gRPC no longer have aprotobufToolsLocator_grpcconfiguration created, so Gradle never attempts to resolveprotoc-gen-grpc-java:null.spring-boot-test-classic-modules—spring-boot-grpc-testhas been removed from the classic modules aggregate. gRPC test support should be pulled in explicitly viaspring-boot-starter-grpc-server-testorspring-boot-starter-grpc-client-test, not bundled into the classic test starter for all projects.A new integration test (
doesNotConfigureGrpcWhenGrpcIsNotPresent) verifies that theprotobufToolsLocator_grpcconfiguration is absent when no gRPC dependency is declared.Fixes gh-50822
Fixes gh-50825