简体   繁体   English

使用 gradle 进行多项目依赖管理

[英]Multiproject dependency management with gradle

There are currently 3 projects/git repos set up with gradle:目前有 3 个项目/git repos 设置了 gradle:

  • app (java, android)应用程序(Java,安卓)
  • backend (java, spring)后端(java,spring)
  • client (java, vaadin)客户端(java,vaadin)

Dependencies:依赖项:

app    -> backend
client -> backend

Since app and client don't depend on everything in backend like they do not depend on spring etc. but on some model classes, I need to find a good solution for building the project.由于appclient不依赖于backend所有内容,就像它们不依赖于 spring 等,而是依赖于某些模型类,因此我需要找到一个很好的解决方案来构建项目。

I thought of ...我想到了...

1. backend artifact 1. backend神器

  • 2 source folders like: src/main/java and src/api/java 2 个源文件夹,如: src/main/javasrc/api/java
  • api source folder compiled as a jar artifact api源文件夹编译为 jar 工件
  • included in app and client包含在appclient

2. extend sourceSets 2. 扩展源集

  • add backend/src/api/java to app and clientbackend/src/api/javaappclient

3. new api project 3.新建api项目

app     -> api
client  -> api
backend -> api

conclusion结论

The first and second solution does not need to have a fourth git repo and I think it's not a bad idea to have the api component in the backend , but in the context of gradle a project dependency like in 3., would be more transparent I think.第一个和第二个解决方案不需要有第四个 git repo,我认为在backendapi组件并不是一个坏主意,但是在 gradle 的上下文中,像 3. 中的项目依赖项会更透明我思考。

Any best practices?任何最佳实践?

Thank you for helping !感谢您的帮助 !

Best practice is option number 3 (create a new api project).最佳实践是选项 3(创建一个新的api项目)。

Side note: You don't need to make a separate repo for the api project, you could keep it alongside the backend project if you wanted.旁注:您不需要为 api 项目制作单独的 repo,如果需要,您可以将它与后端项目一起保存。

Edit: Adding Repo Layout编辑:添加回购布局

If you want to have the api along side the server, you would want this layout.如果您想将 api 放在服务器旁边,您会想要这种布局。 Then reference the API like project(":backend:api")然后引用像project(":backend:api")这样的 API

.
├── app
│   └── build.gradle
├── backend
│   ├── api
│   │   └── build.gradle
│   └── server
│       └── build.gradle
├── build.gradle
├── client
│   └── build.gradle
└── settings.gradle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM