user15433749
user15433749

Reputation:

How can I add jitpack.io as a repository in my build.gradle correctly?

I want to use Stepper-Touch github library. For this I have to add jitpack.io in

allproject{ 
    repositories{
        [here] 
    }
}

in my build.gradle project file. There isn't

allproject{...}

section, so I added it myself, but i got this error

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

Then I looked for answer and found that someone says I should remove

dependencyResolutionManagement

section in my settings.gradle file. I did, but then other dependencies such as constraint layout's, live data's dependencies stopped working. Help me, how can I fix that all? :(

Upvotes: 13

Views: 12734

Answers (1)

Seaney F. Shell
Seaney F. Shell

Reputation: 280

As of the 7.X.X gradle build tools. allprojects is deprecated use of dependencyResolutionManagement is the best practice for declaring repositories in every subproject of your build. Because of this Android projects will no longer generate with allprojects blocks in their project build.gradle files. It will instead generate a dependencyResolutionManagement block in settings.gradle.

You shouldn't experience any issues if you use dependencyResolutionManagement to achieve the same result as an allprojects block. You can add repositories to the dependencyResolutionManagement repositories block just like you would with an allprojects block like so

Kotlin gradle file example

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        // e.g this is how you would add jitpack
        maven {
            url = uri("https://jitpack.io")
        }
    }
}

Groovy gradle file example

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        // e.g this is how you would add jitpack
        maven { url "https://jitpack.io" }
        // Add any repositories you would be adding to all projects here
    }
}

I've listed the old way below, however this may not work with Android Gradle plugin 4.0 or greater

Remove the whole dependencyResolutionManagement block from your settings.gradle so that it looks like

rootProject.name = "My Application"
include ':app'

Then add the the allproject block to your project build.gradle and make sure to add all of the dependencies that were in your dependencyResolutionManagement so in our example it would look like

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon

        // e.g this is how you would add jitpack
        maven { url "https://jitpack.io" }
        // Add any repositories you would be adding to all projects here
    }
}

Upvotes: 28

Related Questions