Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 671
Joel Broström Avatar asked Jun 19 '18 08:06

Joel Broström


People also ask

Does order matter in Gradle dependencies?

The order inside the dependencies { } block is preserved. You are kind of right. Dependency ordering is preserved, but for example all compile dependencies will be before testCompile dependencies no matter of how you order them.

What happens during Gradle build?

During this phase, Gradle identifies the tasks that need to be executed based on the DAG of task objects created in the previous phase, and executes them according to their dependency order. All the build work and activities are actually done in this phase. For example: compiling source code and generating .

How does Gradle resolve transitive dependencies?

Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically. The version selection for transitive dependencies can be influenced by declaring dependency constraints.


1 Answers

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.

like image 160
ScottMcC Avatar answered Oct 16 '22 16:10

ScottMcC