What's the difference in defining "repositories" in build.gradle vs settings.gradle?

Viewed 322

In many of our projects we have the repositories block defined in both build.gradle and settings.gradle, they look like this:

build.gradle

repositories {
    maven {
        url { custom_nexus_repository }
    }
    maven {
        url { custom_repository }
    }
}

settings.gradle

pluginManagement {
    repositories {
        maven {
            url "${custom_repository}"
            allowInsecureProtocol = true
        }
        maven {
            url "${custom_nexus_repository}"
            allowInsecureProtocol = true
        }
    }
}

What's the purpose of defining it in both settings.gradle AND build.gradle? Wouldn't one or the other be sufficient?

1 Answers

Plugin repositories defined in settings.gradle are used for resolving gradle plugins. By default, they can be omitted and default plugin portal will be used https://plugins.gradle.org. Gradle build system has many plugins and you may write your own.

Plugins should be resolved earlier during the build process that's why they are located in separate settings.gradle file, which is executed before build.gradle.

https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:plugin-vs-build-repos

Related