การแก้ข้อขัดแย้งของรุ่นและข้อจำกัดของส่วนพึ่งพา
วิเคราะห์และแก้ความขัดแย้งของรุ่นส่วนพึ่งพาด้วยรายงานส่วนพึ่งพา กลยุทธ์การแก้ไข ข้อจำกัด และรุ่นที่บังคับใช้
การแก้ข้อขัดแย้งของรุ่นและข้อจำกัดของส่วนพึ่งพา เป็นบทเรียน 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 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
The Conflict Problem
Two libraries you depend on may each pull in a different version of the same transitive dependency. Gradle must pick one — and the wrong choice causes runtime errors. Managing this is a core skill.
Default: Newest Wins
By default Gradle resolves a conflict by choosing the highest requested version of a dependency across the graph. Usually safe, but not always.
Seeing the Dependency Tree
The dependencies task prints the full resolved graph, showing which version won and why.
gradle dependencies --configuration runtimeClasspathExplaining a Single Dependency
The dependencyInsight task explains exactly how one dependency was resolved and who requested each version.
gradle dependencyInsight --dependency guavaForcing a Version
You can force a specific version, overriding the conflict resolution, with a resolution strategy.
configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:32.1.3-jre'
}
}Dependency Constraints
The modern approach uses constraints to declare an allowed version without adding the dependency directly — cleaner than force.
dependencies {
constraints {
implementation 'com.google.guava:guava:32.1.3-jre'
}
}Excluding Transitives
Sometimes a transitive dependency is unwanted entirely. Exclude it from the bringing dependency.
implementation('org.example:lib:1.0') {
exclude group: 'commons-logging'
}Rejecting Bad Versions
A resolution strategy can reject known-broken versions so Gradle never selects them.
resolutionStrategy {
componentSelection {
all { if (candidate.version == '1.2.0') reject('known bug') }
}
}Failing on Conflict
For strict reproducibility, tell Gradle to fail the build whenever a version conflict occurs, forcing you to resolve it explicitly.
resolutionStrategy { failOnVersionConflict() }Locking Dependencies
Dependency locking writes resolved versions to a lockfile so builds are fully reproducible across machines and time.
gradle dependencies --write-locksPlatforms and BOMs
Import a published BOM with the platform notation to align many related dependencies on one tested version set, avoiding manual version juggling.
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:3.2.0')
implementation 'org.springframework.boot:spring-boot-starter-web'
}Quick Check
Test your conflict resolution knowledge.
Recap
You learned to manage version conflicts:
- Default resolution picks the highest version
- Inspect with
dependenciesanddependencyInsight - Override with
forceor, preferably,constraints excluderemoves unwanted transitives; reject blocks bad versions- Dependency locking makes builds reproducible
เรียนรู้ 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 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การแก้ข้อขัดแย้งของรุ่นและข้อจำกัดของส่วนพึ่งพา”
วิเคราะห์และแก้ความขัดแย้งของรุ่นส่วนพึ่งพาด้วยรายงานส่วนพึ่งพา กลยุทธ์การแก้ไข ข้อจำกัด และรุ่นที่บังคับใช้ คุณปฏิบัติ 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การประกาศการพึ่งพาของโครงการ
- การแก้ไขการพึ่งพาและแคช
- คลังเก็บแบบกำหนดเองและ BOM
- การแก้ข้อขัดแย้งของรุ่นและข้อจำกัดของส่วนพึ่งพา