0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · Lekcja

Rozwiązywanie konfliktów wersji i ograniczenia zależności

Diagnozuj i naprawiaj konflikty wersji zależności za pomocą raportu zależności, strategii rozwiązywania, ograniczeń i wymuszonych wersji.

Rozwiązywanie konfliktów wersji i ograniczenia zależności to bezpłatna lekcja Groovy & Gradle: JVM Automation and Build Engineering na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Groovy & Gradle: JVM Automation and Build Engineering, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Groovy & Gradle: JVM Automation and Build Engineering zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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 runtimeClasspath

Explaining a Single Dependency

The dependencyInsight task explains exactly how one dependency was resolved and who requested each version.

gradle dependencyInsight --dependency guava

Forcing 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-locks

Platforms 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 dependencies and dependencyInsight
  • Override with force or, preferably, constraints
  • exclude removes unwanted transitives; reject blocks bad versions
  • Dependency locking makes builds reproducible

Często zadawane pytania

Czy lekcja „Rozwiązywanie konfliktów wersji i ograniczenia zależności” jest bezpłatna?

Tak — pełny tekst „Rozwiązywanie konfliktów wersji i ograniczenia zależności” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Groovy & Gradle: JVM Automation and Build Engineering, przejdź na CoddyKit PRO. Kurs Groovy & Gradle: JVM Automation and Build Engineering zawiera 4 lekcji w sumie.

Co nauczysz się w „Rozwiązywanie konfliktów wersji i ograniczenia zależności”?

Diagnozuj i naprawiaj konflikty wersji zależności za pomocą raportu zależności, strategii rozwiązywania, ograniczeń i wymuszonych wersji. Ćwiczysz Groovy & Gradle: JVM Automation and Build Engineering z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Groovy & Gradle: JVM Automation and Build Engineering?

Nie wymagamy żadnego doświadczenia. Groovy & Gradle: JVM Automation and Build Engineering w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Rozwiązywanie konfliktów wersji i ograniczenia zależności”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Groovy & Gradle: JVM Automation and Build Engineering?

Tak. Każda lekcja Groovy & Gradle: JVM Automation and Build Engineering zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Deklarowanie zależności projektu
  2. Rozwiązywanie zależności i buforowanie
  3. Niestandardowe repozytoria i BOM-y
  4. Rozwiązywanie konfliktów wersji i ograniczenia zależności
← Powrót do Groovy & Gradle: JVM Automation and Build Engineering