Skip to content

Fix gRPC auto-configuration when protobuf is used without gRPC#50827

Open
UjjwalChitransh wants to merge 1 commit into
spring-projects:mainfrom
UjjwalChitransh:fix/50822-50825-grpc-protobuf
Open

Fix gRPC auto-configuration when protobuf is used without gRPC#50827
UjjwalChitransh wants to merge 1 commit into
spring-projects:mainfrom
UjjwalChitransh:fix/50822-50825-grpc-protobuf

Conversation

@UjjwalChitransh

Copy link
Copy Markdown

Problem

Two related regressions introduced in 4.1.0 around gRPC/protobuf:

gh-50822Could not find io.grpc:protoc-gen-grpc-java:null

ProtobufPluginAction unconditionally registered a grpc plugin in the Protobuf extension whenever the com.google.protobuf Gradle plugin was detected. This caused Gradle to create a protobufToolsLocator_grpc configuration and try to resolve io.grpc:protoc-gen-grpc-java without 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 reports io.grpc:protoc-gen-grpc-java:null.

gh-50825TypeNotPresentException: Type GrpcServerStartedEvent not present

spring-boot-grpc-test was added to spring-boot-test-classic-modules with transitive = false. This put the GrpcPortInfoApplicationContextInitializer class on the classpath but left its dependency GrpcServerStartedEvent (from spring-grpc) off the classpath. When Spring introspects application listeners at context startup it reads the generic type parameter of ApplicationListener<GrpcServerStartedEvent> via reflection, which throws TypeNotPresentException because the class is absent.

Fix

ProtobufPluginAction — gRPC plugin configuration is now deferred to afterEvaluate and only applied when at least one dependency with group io.grpc is declared in any project configuration. Projects that use protobuf but not gRPC no longer have a protobufToolsLocator_grpc configuration created, so Gradle never attempts to resolve protoc-gen-grpc-java:null.

spring-boot-test-classic-modulesspring-boot-grpc-test has been removed from the classic modules aggregate. gRPC test support should be pulled in explicitly via spring-boot-starter-grpc-server-test or spring-boot-starter-grpc-client-test, not bundled into the classic test starter for all projects.

A new integration test (doesNotConfigureGrpcWhenGrpcIsNotPresent) verifies that the protobufToolsLocator_grpc configuration is absent when no gRPC dependency is declared.

Fixes gh-50822
Fixes gh-50825

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>
@UjjwalChitransh UjjwalChitransh force-pushed the fix/50822-50825-grpc-protobuf branch from 52ee738 to 0e06bd5 Compare June 23, 2026 19:37
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

2 participants