close

[Solved] Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘build.gradle’

Trying to add jitpack.io repo in setting.gradle but I am facing the following error: Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘build.gradle’ in android. In this Exerror article, We are going to learn about How to reproduce this error and we will discuss All Possible Solutions Let’s Get Start With This Article.

How Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘build.gradle’ Error Occurs?

Trying to add jitpack.io repo in setting.gradle but I am facing the following error.

Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘build.gradle’ Error?

  1. How To Solve Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle' Error?

    To Solve Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle' Error Second Solution is You Just need to Remove dependencyResolutionManagement From Your setting.gradle and then After your Gradle Sync, Your error Should be solved. Thanks.

  2. Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'

    To Solve Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle' Error To Solve Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle' Error You Just need to add maven URL as https://jitpack.io/ in your dependencyResolutionManagement as a repository. And now, After your Gradle Sync, Your error will be solved. Thank You.

Solution 1: Add maven in dependencyResolutionManagement 

To Solve Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘build.gradle’ Error You Just need to add maven URL as https://jitpack.io/ in your dependencyResolutionManagement as a repository Just Like This.

dependencyResolutionManagement {

    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

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

}

And now, After your Gradle Sync, Your error will be solved. Thank You.

Solution 2: Remove dependencyResolutionManagement 

Second Solution is You Just need to Remove dependencyResolutionManagement From Your setting.gradle and then After your Gradle Sync, Your error Should be solved. Thanks.

Solution 3: Use RepositoriesMode as PREFER_SETTINGS

If Above both solution is not working then You need to use RepositoriesMode as PREFER_SETTINGS Just like this.

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

Now, Your error will be solved. Thanks.

Conclusion

It’s all About this error. I hope We Have solved Your error. Comment below Your thoughts and your queries. Also, Comment below on which solution worked for you.

Also, Read

Leave a Comment