3

Let us consider the following section of build.gradle file

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

Although I am not very knowledgable on the exact differences between google(), jcenter() and mavenCentral() - according to this post (Android buildscript repositories: jcenter VS mavencentral) jcenter() is a superset of mavenCentral() - thus we can reasonably expect there to be at least some overlap of supported libraries in google(), jcenter() and mavenCentral().

The question now becomes if a desired repository is found in all 3.

implementation 'some_cool_library_found_in_all_3:1.0.0'

How does gradle know which is the "correct" one to download and install from? Is there some simple heuristic (e.g. go from top to bottom). Or are libraries and versions standardized by some protocol across google(), jcenter() and mavenCentral() - making it irrelevant where we get our library from.

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99

1 Answers1

5

The gradle docs contain the following:

A project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module.

Peter Samokhin
  • 864
  • 1
  • 9
  • 19
  • I think there's a slight caveat to this rule in that gradle won't stop until it finds the artifact, not the module. If you had a `foo:bar:1.0@pom` in one repository and `foo:bar:1.0@jar` in another I believe that gradle is smart enough to source the artifacts from both repository. This can be handy if you need to "fix" a pom by storing a tweaked version in a local file repository, ordered before the remote repository (with the "broken" pom). See [here](https://stackoverflow.com/a/49996562/1089967) – lance-java May 01 '18 at 10:00