如何通过gradle和多个gradle项目实施monorepo
我们有几个完整的gradle项目a、B、C、D。这些是微服务,它们将开始共享protobuf生成的java文件。我们正在考虑这样的结构如何通过gradle和多个gradle项目实施monorepo,gradle,bazel,monorepo,Gradle,Bazel,Monorepo,我们有几个完整的gradle项目a、B、C、D。这些是微服务,它们将开始共享protobuf生成的java文件。我们正在考虑这样的结构 A build.gradle (this is a full on gradle build) B build.gradle (this is B's full on gradle) common build.gradle (build the protobuf that is used by A and B) 现在的问题是,我们如何确
A
build.gradle (this is a full on gradle build)
B
build.gradle (this is B's full on gradle)
common
build.gradle (build the protobuf that is used by A and B)
现在的问题是,我们如何确保开发人员在构建公共应用程序时,它也会构建公共应用程序,以防它在git pull上发生更改。B也是一样。settings.gradle文件似乎没有../../:project或类似的东西
我确实记得gradle也提出了一种构建多个gradle项目的方法
理想情况下,当有人更改公共代码时,将启动多个jenkins构建,并验证更改的核心代码没有破坏使用它的任何服务。我不太清楚该怎么做
1. document the things that depend on common
2. use the document to kick off builds of all things depending on common
然后,如果这是增长,你有D依赖于C依赖于common,每个构建都需要启动,从common到C,然后从C的jar和common的jar到D的二进制上游。我知道twitter使用“pants”来实现这一点。谷歌正在使用bazel。也许我会调查这个而不是gradle?或者我们可以把它们混在一起吗?简单地声明对
common
的依赖就足够了:
// Project A's build.gradle
dependencies {
implementation(project(":common"))
}
为了构建a
,需要成功构建common
。如果由于任何原因,common
的构建失败,那么a
的构建也将失败。例如:
$ ./gradlew project-a:build
> Task :common:compileJava FAILED
/Users/cisco/code/example-multi-project/common/src/main/java/common/ExampleCommon.java:6: error: incompatible types: int cannot be converted to String
return 1;
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':common:compileJava'.
> Compilation failed; see the compiler error output for details.
从上面可以看出,当我尝试构建项目a(project-a:build
)时,调用了公共的构建任务(:common:compileJava
)
两个项目a/b/etc都应进行彻底的测试(单元、集成、冒烟等),以确保尽早/经常检测到任何不兼容的更改
您可以在官方指南中阅读有关多项目生成的更多信息: