Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle protoc plugin doesn't find default google proto file

My proto files use default google protocolbuffers types such as struct and timestamp.

Using the default gradle protoc integration, gradle outputs errors because it can not resolve imports:

google/protobuf/struct.proto: File not found.

google/protobuf/timestamp.proto: File not found.

Replacing the default gradle protoc block

protoc {
    artifact = 'com.google.protobuf:protoc:3.3.0'
}

with one specifying where protoc is

protoc {
    path = '/usr/local/bin/protoc'
}

fixes the issue but it is not portable.

Is there any jar dependency or other portable solution that could make the default gradle protoc definition working?

like image 411
david Avatar asked Sep 02 '25 10:09

david


1 Answers

Adding the following dependencies fixes the error:

compile 'com.google.protobuf:protobuf-java:3.4.0'

The dependency provides default google protofiles along the compiled protobuf library.

From Gradle 6+, use implementation:

dependencies {
  // https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
  implementation 'com.google.protobuf:protobuf-java:3.21.10'
}
like image 157
david Avatar answered Sep 04 '25 01:09

david