我們有一個server應用client程式可以相互通信,都用 java 撰寫并用 maven 構建。
它們通過 gRPC 介面進行互動。
server我們對和有不同的依賴情況client:
server client
| |
--> lib-a --> *.protobuf
| |
| --> *.protobuf
--> lib-b
| |
| --> *.protobuf
--> *.protobuf
server包含庫lib-a,而這些庫又lib-b需要. 服務器還需要一些自己的東西。*.protobuf*.protobuf
client需要原始檔案(不僅僅是生成的java*.protobuf源代碼)以從中生成更多代碼(用于兵變)。
我們有原始*.protobuf資源在一個單獨的存盤庫中,現在我們需要以某種方式分發它們。其他依賴全部由 maven ( server->lib-a, server->lib-b)管理
我們有一些選擇如何提供這種依賴關系。
- 從生成類檔案
*.protobuf并將它們作為 maven 工件分發 - 包含包含
*.protobuf為git-submodule的存盤庫
但是對于每個變體,我們都面臨一些問題:
1)的問題:client需要訪問原始*.protobuf檔案以從中生成更多內容(叛變)。有沒有辦法通過 maven 分發原始檔案?我還聽說將生成的代碼作為 maven 工件分發可能是一種不好的做法(?)
problems with 2): we have a git-submodule in lib-a, that would generate all *.class files from *.protobuf and include these generated sources in it's published artifact. The same thing happens in lib-b. If both libraries are released independently, it may happen that they include different versions of the generated sources. This may lead to issues when the server includes both. In contrast to the maven-managed dependency, this is not explicit an there will be no warnings in the compile-process. Moreover, we would like to exclude SNAPSHOT dependencies in our releases (which we currently enforce with maven-enforcer-plugin). Is there some best-practice to achieve the same with git-submodules (my current best idea is to restrict allowed branch names for submodules in CI pipeline ...)
我真的很感激這里的一些建議:)
目前,我也在做自己的閱讀:
*.protobuf通過 maven分發原始檔案(請參閱:在 Maven 專案之間匯入協議緩沖區定義)- 將客戶端生成的代碼也作為工件提供
uj5u.com熱心網友回復:
Maven 和 Gradle protobuf 插件將檔案包含在與編譯生成的檔案 ( ).proto相同的庫中。這允許依賴于單個 jar,它為 protoc 和 javac 提供資產。.jar.class
我建議為您的 .protos 和相關的生成代碼制作 Maven 庫。將其視為普通的 Java 庫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/440901.html
上一篇:關于使用maven打包war時多個依賴jar版本的最佳實踐的問題
下一篇:無法從父級決議junit
