Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import proto files from classpath (JAR) to build another proto file

I want to import a proto file from a gradle dependencies and have next structure (simplified for redability):

dependency-project:
     - models:
           catalog.proto
   
my-project:
     - source:
           client.proto

In a client.proto I want to reuse some models, which defined in a catalog.proto.

syntax = "proto3";
package client;

import "google/protobuf/descriptor.proto";
import "classpath/catalog.proto"; // ???
...

My build.gradle.kts:

dependencies {
   ...
    implementation("com.google.protobuf:protobuf-java:$protoBufCoreVersion")
    implementation("com.thesamet.scalapb.common-protos:proto-google-common-protos-scalapb_0.9_2.13:2.5.0-3") // trying to reuse
}

apply(plugin = "com.google.protobuf")

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:$protoBufCoreVersion"
        /// probably here I need to use new lib
    }
}
...

But have next problems:

  1. I can see catalog.proto in a classpath, but cannot import it from scratch
  2. catalog.proto don't have any package declaration

As far as I know, there are some available solutions for scala, but I'm using gradle in Java/Kotlin project with gradle and don't understand how to reuse such approach. Also, I found that such usage of proto files (for building new models using .proto files) is not convinient. Is it possible at all?

like image 954
Aleksandr T Avatar asked Nov 28 '25 17:11

Aleksandr T


1 Answers

In case anyone still need it: you need to use Protobuf Plugin for Gradle, check out my answer here for more details: https://stackoverflow.com/a/73822802/2185783.

like image 145
maximus Avatar answered Dec 01 '25 07:12

maximus