Groovy & Gradle: JVM Automation and Build Engineering · 课时

组合构建与构建组合

使用组合构建(includeBuild)将独立的 Gradle 构建合并为一个整体,让您无需发布构件即可共同开发和测试相互依赖的项目。

第 4 / 4 课13 个步骤

组合构建与构建组合 是 CoddyKit 上的免费 Groovy & Gradle: JVM Automation and Build Engineering 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Groovy & Gradle: JVM Automation and Build Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Groovy & Gradle: JVM Automation and Build Engineering 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

What is a Composite Build?

A composite build stitches multiple otherwise-independent Gradle builds together. Unlike subprojects, each included build keeps its own settings.gradle and lifecycle.

  • Subprojects: one build, many modules
  • Composite: many builds, joined on demand

Why Use Composites?

Composite builds shine when you work across repository boundaries:

  • Develop a library and its consumer side by side
  • Avoid publishing SNAPSHOTs just to test a change
  • Debug a plugin in the context of a real project

includeBuild Basics

You join another build with includeBuild in settings.gradle. The path points at a directory containing its own settings file.

includeBuild("../shared-library")

Dependency Substitution

The magic is automatic dependency substitution. When your project declares a dependency on a module that an included build produces, Gradle wires the in-source build in place of the published artifact.

dependencies {
    implementation("com.acme:shared-library:1.0")
}

Explicit Substitution

If group/name do not match, declare the mapping manually so Gradle knows which project replaces the coordinate.

includeBuild("../shared-library") {
    dependencySubstitution {
        substitute(module("com.acme:shared")).using(project(":"))
    }
}

Running Tasks Across Builds

You can invoke tasks from an included build using the :buildName:task syntax from the root.

gradle :shared-library:build

Composite vs Multi-Project

Use a multi-project build when modules always ship together. Use a composite when builds are independently versioned and released but you occasionally need them linked.

Plugin Development Workflow

Composite builds are the recommended way to test a custom plugin. Include the plugin build, and consuming projects pick up your local changes instantly.

includeBuild("../my-gradle-plugin")

IDE Behavior

IntelliJ IDEA and Android Studio import composite builds as a single workspace, so navigation, refactoring, and debugging span all included builds seamlessly.

Limitations to Know

A few constraints apply:

  • Included builds cannot themselves define the same root build
  • A build cannot include itself (no cycles)
  • Publishing tasks are not substituted, only consumable artifacts

Best Practices

Keep composites ergonomic:

  • Use relative paths so teammates can clone side by side
  • Keep coordinates consistent to rely on automatic substitution
  • Document which builds are expected to be included

Quick Check

Test your understanding of composite builds.

Recap

You learned composite builds:

  • includeBuild joins independent builds
  • Dependency substitution swaps artifacts for live source
  • Ideal for cross-repo and plugin development
  • Differs from multi-project: builds stay independently versioned
免费开始

用 AI 导师学习 Groovy — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「组合构建与构建组合」课时是免费的吗?

是的 — 「组合构建与构建组合」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Groovy & Gradle: JVM Automation and Build Engineering 课程的其余内容,请升级到 CoddyKit PRO。 Groovy & Gradle: JVM Automation and Build Engineering 课程共包含 4 节课。

「组合构建与构建组合」这节课中我会学到什么?

使用组合构建(includeBuild)将独立的 Gradle 构建合并为一个整体,让您无需发布构件即可共同开发和测试相互依赖的项目。 你通过在浏览器中直接运行的动手代码来练习 Groovy & Gradle: JVM Automation and Build Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Groovy & Gradle: JVM Automation and Build Engineering 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Groovy & Gradle: JVM Automation and Build Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「组合构建与构建组合」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Groovy & Gradle: JVM Automation and Build Engineering 课中编写并运行代码吗?

能。每节 Groovy & Gradle: JVM Automation and Build Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 单体仓库项目结构
  2. 子项目与配置
  3. 项目间依赖
  4. 组合构建与构建组合
← 返回 Groovy & Gradle: JVM Automation and Build Engineering