Instead of declaring repositories in every subproject of your build or via an allprojects block, Gradle provides a way to declare them centrally for all projects.
| Central declaration of repositories is an incubating feature. |
You can declare repositories that will be used by convention in every subproject in the settings.gradle(.kts) file:
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
The dependencyResolutionManagement repositories block accepts the same notations as in a project, including Maven or Ivy repositories, with or without credentials.
Repositories mode
By default, repositories declared in a project’s build.gradle(.kts) file will override those declared in settings.gradle(.kts).
However, you can control this behavior using the repositoriesMode setting:
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.PREFER_PROJECT
}
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.PREFER_PROJECT
}
Available modes
There are three modes for dependency resolution management:
| Mode | Description | Default? | Use-Case |
|---|---|---|---|
|
Repositories declared in a project override those declared in |
Yes |
Useful when teams need to use different repositories specific to their subprojects. |
|
Repositories declared in |
No |
Useful for enforcing the use of approved repositories across large teams. |
|
Declaring a repository in a project triggers a build error. |
No |
Strictly enforces the use of repositories declared in |
You can change the behavior to prefer the repositories in settings.gradle(.kts):
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.PREFER_SETTINGS
}
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.PREFER_SETTINGS
}
Gradle will warn you if a project or plugin declares a repository when using this mode.
To enforce that only repositories declared in settings.gradle(.kts) are used, you can configure Gradle to fail the build when a project plugin is declared:
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
}
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
}