Align protoc version with protobuf-java

Update `ProtobufPluginAction` to align the protoc version with
`protobuf-java` rather than `protobuf-java-util`. The util
jar is only required for server gRPC code.

See gh-50405

Signed-off-by: Dongliang Xie <dragonfsky@gmail.com>
This commit is contained in:
Dongliang Xie
2026-05-12 08:58:47 -07:00
committed by Phillip Webb
parent b23ad48047
commit 6d307ed250
3 changed files with 22 additions and 3 deletions
@@ -41,6 +41,7 @@ import org.jspecify.annotations.Nullable;
* applied.
*
* @author Andy Wilkinson
* @author Dongliang Xie
*/
final class ProtobufPluginAction implements PluginApplicationAction {
@@ -49,7 +50,7 @@ final class ProtobufPluginAction implements PluginApplicationAction {
private static final Dependency grpcDependency = new Dependency("io.grpc", "protoc-gen-grpc-java");
private static final List<VersionAlignment> versionAlignment = List.of(
protocDependency.alignVersionWith("com.google.protobuf", "protobuf-java-util"),
protocDependency.alignVersionWith("com.google.protobuf", "protobuf-java"),
grpcDependency.alignVersionWith("io.grpc", "grpc-util"));
@Override
@@ -16,6 +16,10 @@
package org.springframework.boot.gradle.plugin;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.jupiter.api.TestTemplate;
import org.springframework.boot.gradle.junit.GradleCompatibility;
@@ -27,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Integration tests for {@link ProtobufPluginAction}.
*
* @author Andy Wilkinson
* @author Dongliang Xie
*/
@GradleCompatibility
class ProtobufPluginActionIntegrationTests {
@@ -59,6 +64,20 @@ class ProtobufPluginActionIntegrationTests {
.contains("com.google.protobuf:protoc:null -> 4.34.0");
}
@TestTemplate
void generatesProtoSourcesWhenProtobufJavaProvidesProtocVersion() throws IOException {
File proto = new File(this.gradleBuild.getProjectDir(), "src/main/proto/example.proto");
proto.getParentFile().mkdirs();
Files.writeString(proto.toPath(), """
syntax = "proto3";
option java_package = "com.example";
message Example {
string name = 1;
}
""");
this.gradleBuild.build("generateProto");
}
@TestTemplate
void alignsVersionOfGrpcDependency() {
assertThat(this.gradleBuild.build("dependencies", "--configuration", "protobufToolsLocator_grpc").getOutput())
@@ -29,7 +29,7 @@ repositories {
}
dependencies {
implementation("com.google.protobuf:protobuf-java-util:4.34.0")
implementation("com.google.protobuf:protobuf-java:4.34.0")
implementation("io.grpc:grpc-util:1.79.0")
}
@@ -60,4 +60,3 @@ tasks.register("generateProtoTasksGrpcPluginOptions") {
tasks.withType(com.google.protobuf.gradle.GenerateProtoTask).each { println "${it.name}: ${it.pluginsForCaching.collect { it.options }}" }
}
}