Importing protocol buffer definitions between Maven projects

后端 未结 2 1589
后悔当初
后悔当初 2021-02-02 17:26

I currently manage a few separate Maven projects in which I use Protobufs as a serialization format and over the wire. I am using David Trott\'s maven-protoc plugin to generate

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 17:57

    I've found another way to achieve, and it doesn't involve any Maven magic. Diving into the code for the maven-protoc plugin, I found that this is a supported use case -- the plugin will look for and collect and .proto files in dependent jars and unpack them into a temporary directory. That directory is then set as an import path to the protoc invocation.

    All that needs to happen is for the .proto file to be included in the dependency's package, which I did by making it a resource:

    projects/a/src/main/resources/a.proto

    Now in projects/b/pom.xml, add 'a' as a regular Maven dependency and just import a.proto from b.proto as if it existed locally:

    b.proto: import "a.proto";

    This isn't ideal, since files names may clash between various projects, but this should occur rarely enough.

提交回复
热议问题