Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with adding repositories in build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        maven { url "https://jitpack.io" }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

This is the error i am getting

A problem occurred evaluating root project 'LuckyMuch'.

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

  • Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.
like image 745
Ripu Kumar Avatar asked Oct 15 '22 20:10

Ripu Kumar


People also ask

What is repositories in build Gradle?

Popular public repositories include Maven Central and the Google Android repository. Gradle provides built-in shorthand notations for these widely-used repositories. Under the covers Gradle resolves dependencies from the respective URL of the public repository defined by the shorthand notation.


2 Answers

Even I faced this issue, I have updated settings.gradle file with below code it worked for me

dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
     repositories {
         google()
         mavenCentral()
     }
}
rootProject.name = "Chat App"
include ':app'
like image 138
Muralikrishna G S Avatar answered Oct 27 '22 12:10

Muralikrishna G S


I have the same problem and solved it. Go to settings.gradle file -> change below code: From this:

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

to this:

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

and add this line in the repository block: maven { url 'https://jitpack.io' }

like image 42
Nikunj Patel Avatar answered Oct 27 '22 11:10

Nikunj Patel