Build Komposit dan Komposisi Build
Gabungkan build Gradle independen menjadi satu menggunakan build komposit (includeBuild), sehingga Anda dapat mengembangkan dan menguji proyek yang saling bergantung tanpa menerbitkan artefak.
Build Komposit dan Komposisi Build adalah pelajaran Groovy & Gradle: JVM Automation and Build Engineering gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Groovy & Gradle: JVM Automation and Build Engineering, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Groovy & Gradle: JVM Automation and Build Engineering mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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:buildComposite 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:
includeBuildjoins independent builds- Dependency substitution swaps artifacts for live source
- Ideal for cross-repo and plugin development
- Differs from multi-project: builds stay independently versioned
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Build Komposit dan Komposisi Build” gratis?
Ya — teks lengkap “Build Komposit dan Komposisi Build” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Groovy & Gradle: JVM Automation and Build Engineering, upgrade ke CoddyKit PRO. Kursus Groovy & Gradle: JVM Automation and Build Engineering mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Build Komposit dan Komposisi Build”?
Gabungkan build Gradle independen menjadi satu menggunakan build komposit (includeBuild), sehingga Anda dapat mengembangkan dan menguji proyek yang saling bergantung tanpa menerbitkan artefak. Kamu berlatih Groovy & Gradle: JVM Automation and Build Engineering dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Groovy & Gradle: JVM Automation and Build Engineering?
Tidak diperlukan pengalaman sebelumnya. Groovy & Gradle: JVM Automation and Build Engineering di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.
Berapa lama pelajaran “Build Komposit dan Komposisi Build” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Groovy & Gradle: JVM Automation and Build Engineering ini?
Ya. Setiap pelajaran Groovy & Gradle: JVM Automation and Build Engineering menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Struktur Proyek Monorepo
- Subproyek & Konfigurasi
- Dependensi Antarproyek
- Build Komposit dan Komposisi Build