バージョン競合と依存関係制約の解決
依存関係レポート、解決戦略、制約、強制バージョンを使って、依存関係のバージョン競合を診断・修正します。
「バージョン競合と依存関係制約の解決」はCoddyKit上の無料Groovy & Gradle: JVM Automation and Build Engineeringレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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
AI チューターと学ぶ Groovy — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「バージョン競合と依存関係制約の解決」レッスンは無料ですか?
はい。「バージョン競合と依存関係制約の解決」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Groovy & Gradle: JVM Automation and Build Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Groovy & Gradle: JVM Automation and Build Engineeringコースには全4レッスンが含まれています。
「バージョン競合と依存関係制約の解決」で何を学びますか?
依存関係レポート、解決戦略、制約、強制バージョンを使って、依存関係のバージョン競合を診断・修正します。 ブラウザで直接実行するハンズオンコードでGroovy & Gradle: JVM Automation and Build Engineeringを演習し、24時間対応の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フィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- プロジェクトの依存関係を宣言する
- 依存関係の解決とキャッシュ
- カスタムリポジトリとBOM
- バージョン競合と依存関係制約の解決