Search code examples
androidgoogle-apiandroid-gradle-pluginbuild.gradlejcenter

Why does the order of imported repositories in build.gradle make or break the project?


Please explain why the first code gives me syncing errors while the second doesn't.

allprojects {
    repositories {
        jcenter()
        google()
    }
}

Failed to resolve: play-services-base Open File

Failed to resolve: play-services-tasks Open File

Changing the repository order syncs just fine:

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Can someone give me a reason or educated guess why this occurs?


Solution

  • This doc might be of use for you:

    https://docs.gradle.org/current/userguide/declaring_repositories.html

    Right down the bottom it mentions:

    Note: The order of declaration determines how Gradle will check for dependencies at runtime. If Gradle finds a module descriptor in a particular repository, it will attempt to download all of the artifacts for that module from the same repository. You can learn more about the inner workings of Gradle’s resolution mechanism.