Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
Asked Answered
G

4

5

A problem occurred evaluating root project when adding allprojects{}. Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

Here is the code in build.gradle

buildscript {
repositories {
    google()
    mavenCentral()

}
dependencies {
    classpath "com.android.tools.build:gradle:7.0.0"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
}

allprojects {
repositories {
    google()
    mavenCentral()
    maven { url 'https://jitpack.io' }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Guarantor answered 27/10, 2021 at 6:20 Comment(0)
G
14

For Android Studio Arctic Fox |2020.3.1 Remove this from the build.gradle

allprojects {
repositories {
    google()
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

} Go to settings.gradle and add follwing line

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
    google()
    mavenCentral()
    jcenter()
    maven { url 'https://jitpack.io' }
}

}

Guarantor answered 27/10, 2021 at 6:20 Comment(1)
This solution solved my problem! Thanks a lot for you answer! \O/Handel
H
0

For Spring Boot gradle project this one of the ways by which you can specify build.gradle

buildscript {

repositories {
    mavenCentral()
maven {
            url can be given like this "https://plugins.gradle.org/"
        }
}
dependencies {
    classpath "com.android.tools.build:gradle:7.0.0"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
}
Hornbook answered 27/10, 2021 at 6:39 Comment(0)
A
0

Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

Astridastride answered 10/9, 2022 at 14:29 Comment(0)
B
0

Go to settings.gradle and update as shown

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
    google()
    mavenCentral()
    jcenter()
    maven { url 'https://jitpack.io' }
}
Britton answered 24/2, 2023 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.