การสร้างแบบผสมและการประกอบการสร้าง
รวมการสร้าง Gradle ที่เป็นอิสระเข้าด้วยกันด้วยการสร้างแบบผสม (includeBuild) เพื่อให้พัฒนาและทดสอบโครงการที่พึ่งพากันได้ร่วมกันโดยไม่ต้องเผยแพร่สิ่งส่งมอบ
การสร้างแบบผสมและการประกอบการสร้าง เป็นบทเรียน Groovy & Gradle: JVM Automation and Build Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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: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
เรียนรู้ Groovy ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การสร้างแบบผสมและการประกอบการสร้าง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การสร้างแบบผสมและการประกอบการสร้าง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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 ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- โครงสร้างโครงการโมโนรีโป
- โครงการย่อยและการกำหนดค่า
- การพึ่งพาระหว่างโครงการ
- การสร้างแบบผสมและการประกอบการสร้าง