skip to content

What is centralized repository management in Gradle, and where do you configure it?

level: juniorimportance: must knowfreq 55%

answer

  1. settings.gradle.kts not build.gradle.kts
  2. dependencyResolutionManagement { repositories {} }
  3. added in Gradle 6.8
  4. one place for the whole build
  5. separate from pluginManagement.repositories

basics

~10 s

It's declaring repositories once for the whole build inside settings.gradle.kts using dependencyResolutionManagement { repositories {} }, instead of repeating repositories {} in every project's build.gradle.kts.

solid answer

~40 s

Centralized repository management lets you declare all dependency repositories in one place — the `dependencyResolutionManagement { repositories { } }` block in `settings.gradle.kts` — so every subproject resolves dependencies from the same set without each `build.gradle.kts` repeating its own `repositories {}` block. It was introduced in Gradle 6.8. The settings file is evaluated once, before any project is configured, so it's the natural home for build-wide concerns. This removes duplication, guarantees consistency across modules, and gives you a single audit point for which repositories the build is allowed to use. You can pair it with a `repositoriesMode` to actively forbid project-level repositories, turning the central list into the single source of truth.

code

kotlin · 8 lines
kotlin
// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        mavenCentral()
        google()
        maven { url = uri("https://repo.mycorp.com/releases") }
    }
}

go deeper

for a junior

Know it lives in settings.gradle.kts under dependencyResolutionManagement { repositories {} } and removes per-module duplication.

for a middle

Explain the init-phase rationale and that it's distinct from pluginManagement and buildscript repositories.

for a senior

Tie it to governance/auditability and mention repositoriesMode for enforcement.

for a principal

Frame it as org-wide dependency policy: a single audited repository surface enforced across all teams' builds.

## The problem it solves In a multi-module Gradle build, dependencies are downloaded from **repositories** (Maven Central, Google's Maven repo, internal Artifactory/Nexus, etc.). Traditionally each module declared its own `repositories { }` block inside its `build.gradle.kts`. In a 30-module build that meant the same `mavenCentral()` line copy-pasted 30 times — easy to drift, hard to audit, and a security hole because any module could quietly add a new repository. ## The mechanism Gradle's `settings.gradle.kts` is evaluated **once**, before any project is configured, during the *initialization* phase. Because of that, it's the right place for build-wide policy. Gradle 6.8 added a settings-level block: ```kotlin // settings.gradle.kts dependencyResolutionManagement { repositories { mavenCentral() google() } } ``` Once declared here, **every** subproject resolves its production dependencies from this set; no `repositories {}` is needed in any `build.gradle.kts`. ## Key distinctions - `dependencyResolutionManagement.repositories` controls repositories for **regular (production) dependencies**. - It is *separate* from `pluginManagement.repositories`, which controls where **plugins** are fetched. - `buildscript { repositories {} }` (legacy plugin/classpath resolution) is also separate. ## Enforcement The block also exposes `repositoriesMode`, a `Property<RepositoriesMode>`. Setting it to `RepositoriesMode.FAIL_ON_PROJECT_REPOS` makes the build **fail** if any project also declares its own repositories — making the central list authoritative. The default is `PREFER_PROJECT` (project repos win and the central ones are ignored for that project). ## Why teams adopt it - **Consistency**: every module sees the same repositories, so resolution is reproducible. - **Governance/security**: one audited list; no rogue repo slipping in. - **Maintenance**: change a URL or add an internal mirror in one file.

  • Does this block also control where plugins are downloaded from?
    No. Plugin repositories are configured in pluginManagement { repositories {} }, a separate settings block. dependencyResolutionManagement only governs regular project dependencies.
  • Since which Gradle version is it available?
    Gradle 6.8 introduced dependencyResolutionManagement and the repositoriesMode property.

saying these in an interview costs you the question

  • Claiming the block goes in the root build.gradle.kts — it belongs in settings.gradle.kts.
  • Confusing it with pluginManagement.repositories, which is for plugins.

context