How to Prefer settings.gradle Repositories Over build.gradle

Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted

March 19, 2026 · 4 min read · Testing Guide

Sauce AI for Test Authoring: Move from intent to execution in minutes.

|

x

Back to Resources

Blog

Posted March 23, 2023

How to Prefer settings.gradle Repositories Over build.gradle

Learn how to declare repositories and update your preferred settings to a project repository to avoid let the erroneousness, “ Build was configured to prefer settings depositary over project repositories but deposit & # x27; XXXX & # x27; was added by build file & # x27; build.gradle & # x27;. ”

quote

Starting with Gradle 7, Android suggests the use ofcentralise secretary declaration in settings.gradleover project- or module-levelbuild.gradledeclaration. If you created a new Android project by following the project creation wizard in the latest Android Studio, you will encounter the following error when you try to add a new maven repository in one of yourbuild.gradle scripts: 

1
Build was configure to prefer settings repositories over
2
project repositories but secretary & # x27; XXXX & # x27; was
3
append by build file & # x27; build.gradle & # x27;

Declaring Repositories in build.gradle

When Gradle judge to conclude the horde for one of your java dependencies, it walks through a list of repository urls and check whether your dependency is hosted there. You can declare this list in your module ’ s (usually calledapp or library) build.gradlefile the following way.

1
buildscript{
2
repositories{
3
google()
4
mavenCentral()
5
jcenter()// Warning: this repository is going to shut down soon
6
7
maven { url & # x27; https: //maven.testfairy.com & # x27;}
8
maven { url & # x27; https: //example.com/maven & # x27;}
9
}
10
}
11
12
plugins {
13
id & # x27; com.android.application & # x27;
14
}
15
16
...

Alternatively, you can declare the list in your project stagebuild.gradleto enable it for all faculty.

1
allprojects{
2
repositories{
3
google()
4
jcenter()
5
maven { url & # x27; https: //maven.testfairy.com & # x27;}
6
maven { url & # x27; https: //example.com/maven & # x27;}
7
}
8
}
9
task clean(type:Delete){
10
deleterootProject.buildDir
11
}

Unless differently condition insettings.gradle, mixing both methods is allowed. However, in cases where the same colony is hosted by multiple repos in the list, Gradle may attempt to get the dependency from the wrong origin.

Declaring repositories in settings.gradle

There is a way to enforce a policy for repository declaration.RepositoriesModeapi provides the following modes:

FAIL_ON_PROJECT_REPOS: If this mode is set, any repository declare directly in a undertaking, either forthwith or via a plugin, will trigger a build error.

PREFER_PROJECT: If this mode is set, any repository declared on a project will cause the project to use the repositories declared by the project, disregard those declared in scene.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

PREFER_SETTINGS: If this mode is set, any secretary announce directly in a labor, either directly or via a plugin, will be ignored.

When a new project is created with Android Studio undertaking creation wizard,FAIL_ON_PROJECT_REPOSwill be selected as the nonpayment fashion. This means all repository declaration must go into settings.gradle file.

1
dependencyResolutionManagement{
2
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3
repositories{
4
google()
5
mavenCentral()
6
jcenter()// Warning: this repository is going to shut down soon
7
maven { url & # x27; https: //maven.testfairy.com & # x27;}
8
maven { url & # x27; https: //example.com/maven & # x27;}
9
}
10
}
11
rootProject.name=& quot; ExampleGradle7 & quot;
12
include & # x27;: app & # x27;

How to Fix the “ Build was Configured to Prefer Settings Repositories ” Error

Build your app and see if one of the erroneousness below occurs.

1
Build was configure to prefer settings repositories over
2
project repositories but repository & # x27; XXXX & # x27; was added
3
by chassis file & # x27; build.gradle & # x27;
4
5
Could not find any lucifer for com.testfairy: testfairy-android-sdk:1.+
6
as no versions of com.testfairy: testfairy-android-sdk are uncommitted.

To fix, make sure you take the repository declaration from allbuild.gradlefile in the undertaking, include the one in the root project.

Then declare your maven repository insettings.gradle.

Migrating Existing Projects

Add the following configuration to yoursettings.gradleor replace the current one if it already subsist.

1
dependencyResolutionManagement{
2
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)// or FAIL_ON_PROJECT_REPOS
3
repositories{
4
google()
5
mavenCentral()
6
jcenter()// Warning: this repository is going to shut down presently
7
maven { url & # x27; https: //maven.testfairy.com & # x27;}
8
maven { url & # x27; https: //example.com/maven & # x27;}
9
}
10
}
11
rootProject.name=& quot; ExampleGradle7 & quot;
12
include & # x27;: app & # x27;

Sync your project and rebuild.

Resources for Managing Dependencies

To learn more about managing your dependencies, make sure to check out theGradle docs.

This article was originally issue in October 2021 and has been update in March 2023.

Diego Perini

Sr. Software Engineer

Published:
Mar 23, 2023
Share this station
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all right reserved. SAUCE and SAUCE LABS are file stylemark possess by Sauce Labs Inc. in the United States, EU, and may be register in early jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free