0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · Урок

Композитные сборки и композиция сборок

Объединяйте независимые сборки Gradle в одну с помощью композитных сборок (includeBuild), разрабатывая и тестируя взаимозависимые проекты вместе без публикации артефактов.

«Композитные сборки и композиция сборок» — бесплатный урок Groovy & Gradle: JVM Automation and Build Engineering на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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

Часто задаваемые вопросы

Урок «Композитные сборки и композиция сборок» бесплатный?

Да — полный текст урока «Композитные сборки и композиция сборок» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Groovy & Gradle: JVM Automation and Build Engineering, подпишись на CoddyKit PRO. Курс Groovy & Gradle: JVM Automation and Build Engineering содержит 4 уроков всего.

Чему я научусь в уроке «Композитные сборки и композиция сборок»?

Объединяйте независимые сборки Gradle в одну с помощью композитных сборок (includeBuild), разрабатывая и тестируя взаимозависимые проекты вместе без публикации артефактов. Ты практикуешь Groovy & Gradle: JVM Automation and Build Engineering с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Groovy & Gradle: JVM Automation and Build Engineering?

Предыдущий опыт не требуется. Groovy & Gradle: JVM Automation and Build Engineering на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 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