Gradle 嵌套项目设置

Gradle nested projects setup

如何设置这样一个项目结构,其中我有名为“app”、“frontend”和“backend”的根项目以及每个项目中的库项目。然后 运行 一个构建任务会给我一个后端 jar 和一个 swing(例如)jar 应用程序。

像这样:

然后 运行:gradle build 并且有 build/.../frontend.jarbuild/.../backend.jar

我确实尝试在 settings.gradle 中使用 include 但这似乎不起作用(至少 gradle projects 和 intellij idea 不识别 frontend 中的项目和 backend)。我有:

root/settings.gradle 与:include 'frontend', 'backend' root/backend/settings.gradle 与:include 'library', 'main' frontend

也一样

有多种方法。根部的一种方式 settings.gradle (gradle v7.1)

rootProject.name = 'test-prj-tree'
include 'backend'
include 'frontend'
include 'library'
include 'backend:library'
findProject(':backend:library')?.name = 'backend-lib'
include 'backend:main'
findProject(':backend:main')?.name = 'backend-main'
include 'frontend:library'
findProject(':frontend:library')?.name = 'frontend-lib'
include 'frontend:main'
findProject(':frontend:main')?.name = 'frontend-main'

在现代 Gradle 中可以 includeBuild,完美解决了问题:

// root/settings.gradle.kts
rootProject.name = "root"

includeBuild("backend")
includeBuild("frontend")
// root/backend/settings.gradle.kts and root/frontend/settings.gradle.kts

include(":library")
include(":main")