多模块 Gradle 项目

发布于 2025-01-11 03:58:56 字数 1185 浏览 0 评论 0原文

我目前正在构建一个具有多个分布式 api(通过 Java Spring Boot)的客户端-服务器应用程序,并且我已经抽象了 API 组件(@Controller、@Service @Mapper 和 @Repository)。

我有一个多模块 gradle 项目,看起来像这样:

---- Projects
------ properties.gradle
------ settings.gradle
------ ClientProj
-------- ClientApplication
-------- build.gradle
------ ApiProj1
-------- ApiProj1Application
-------- build.gradle
------ ApiProj2
-------- ApiProj2Application
-------- build.gradle
------ common
-------- build.gradle
------ api-components
-------- build.gradle

但我想可能做这样的事情: (请注意,我试图将所有 api 相关组件包装在一起)。

---- Projects
------ properties.gradle
------ settings.gradle
------ ClientProj
-------- ClientApplication
-------- build.gradle
------ common
-------- build.gradle
------ api
-------- ApiProj1
---------- ApiProj1Application
---------- build.gradle
-------- ApiProj2
---------- ApiProj2Application
---------- build.gradle
------- api-components
---------- build.gradle

从我在网上看到的情况来看,我没有注意到其他模块中的多模式,就像我用 API 展示的最后一个示例。想请问大家这样的设计是否可以接受,如果可以的话,这些嵌套的api模块是否会被视为子项目。从我迄今为止不成功的尝试来看,以这种方式构建时,访问嵌套项目似乎真的很困难。

对于使用 Gradle,我还算初级,但多模块和子项目对我来说是新的,我认为它在隔离问题和组织代码方面有很大的潜力。任何反馈将不胜感激!先感谢您。 :)

I'm currently building a client-server app with multiple distributed apis (via Java Spring Boot), and I've abstracted the API components (@Controller, @Service @Mapper, and @Repository).

I have a multi-module gradle project that looks something like this:

---- Projects
------ properties.gradle
------ settings.gradle
------ ClientProj
-------- ClientApplication
-------- build.gradle
------ ApiProj1
-------- ApiProj1Application
-------- build.gradle
------ ApiProj2
-------- ApiProj2Application
-------- build.gradle
------ common
-------- build.gradle
------ api-components
-------- build.gradle

But I want to possibly do something like this instead:
(Notice that I'm trying to wrap all the api related components together).

---- Projects
------ properties.gradle
------ settings.gradle
------ ClientProj
-------- ClientApplication
-------- build.gradle
------ common
-------- build.gradle
------ api
-------- ApiProj1
---------- ApiProj1Application
---------- build.gradle
-------- ApiProj2
---------- ApiProj2Application
---------- build.gradle
------- api-components
---------- build.gradle

From what I've seen online, I haven't noticed multimodes within other modules like the last example I show with the api. I'd like to ask everyone whether this design is acceptable, and if so, whether these nested api modules would be considered subprojects. From my unsuccessful attempts thus far, it seems really difficult to access nested projects when constructed this way.

I'm a bit more than beginner for using Gradle but multimodules and subprojects are new to me and I think has a lot of potential to isolate concerns and organize code. Any feedback would be greatly appreciated! Thank you in advance. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖风昔人 2025-01-18 03:58:56

仍然可以使用第二种结构。您的第一个结构的 settings.gradle.kts 必须类似于:

include(
    "ClientProj",
    "common",
    "ApiProj1",
    "ApiProj2",
    "api-components",
)

对于第二个结构,应将其更改为:

include(
    "ClientProj",
    "common",
    "ApiProj1",
    "ApiProj2",
    "api-components",
)

project(":ApiProj1").projectDir = file("api/ApiProj1")
project(":ApiProj2").projectDir = file("api/ApiProj2")
project(":api-components").projectDir = file("api/api-components")

It's still possible to use the second structure. Your first structure's settings.gradle.kts must be like:

include(
    "ClientProj",
    "common",
    "ApiProj1",
    "ApiProj2",
    "api-components",
)

For the second, it should be changed to:

include(
    "ClientProj",
    "common",
    "ApiProj1",
    "ApiProj2",
    "api-components",
)

project(":ApiProj1").projectDir = file("api/ApiProj1")
project(":ApiProj2").projectDir = file("api/ApiProj2")
project(":api-components").projectDir = file("api/api-components")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文