Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.gradle.api.artifacts.DependencyResolveDetails;
import org.gradle.api.artifacts.ModuleVersionSelector;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.result.DependencyResult;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.jspecify.annotations.Nullable;

Expand All @@ -42,6 +41,7 @@
* applied.
*
* @author Andy Wilkinson
* @author Dongliang Xie
*/
final class ProtobufPluginAction implements PluginApplicationAction {

Expand All @@ -50,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
Expand Down Expand Up @@ -141,9 +141,8 @@ private Optional<String> versionFromRuntimeClasspath(Project project, Dependency
.getByName("runtimeClasspath")
.getIncoming()
.getResolutionResult()
.getAllDependencies()
.getAllComponents()
.stream()
.map(DependencyResult::getFrom)
.map(ResolvedComponentResult::getId)
.filter(ModuleComponentIdentifier.class::isInstance)
.map(ModuleComponentIdentifier.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +31,7 @@
* Integration tests for {@link ProtobufPluginAction}.
*
* @author Andy Wilkinson
* @author Dongliang Xie
*/
@GradleCompatibility
class ProtobufPluginActionIntegrationTests {
Expand Down Expand Up @@ -59,6 +64,20 @@ void alignsVersionOfProtocDependency() {
.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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -60,4 +60,3 @@ tasks.register("generateProtoTasksGrpcPluginOptions") {
tasks.withType(com.google.protobuf.gradle.GenerateProtoTask).each { println "${it.name}: ${it.pluginsForCaching.collect { it.options }}" }
}
}