1

So I am working on an old project in which I have the following code in the project build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Android Studio is warning me to use mavenCentral() instead of jcenter() as jcenter is not being updated. So I have change it to the following code:

buildscript {
    repositories {
        google()
        mavenCentral()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

So my question is, if now I am using mavenCentral() instead of jcenter(), do I have to use the " maven { url "https://jitpack.io" }" line of code or I should´t use it? I mean, the correct code would be the following instead of the previous code? ->

buildscript {
    repositories {
        google()
        mavenCentral()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Or actually I should use the code line of maven jitpack (maven { url "https://jitpack.io" }") although now I am using mavenCentral() instead of jcenter()?

  • If it breaks when you remove `maven { url "https://jitpack.io" }` then I think you know the answer. If it doesn't break, then I have no idea why you would keep it. Best of luck! – Elliott Frisch Aug 20 '22 at 20:02
  • @ElliottFrisch I am confused. So I would like an awnser with an explenation better that trying to removing jitpack and see if my app breaks, I think that it is not a good solution to know if I have to use it or not because maybe my app seemingly is working without it but in fact it is causing some crashes that I can´t see only seeing if ir breaks or not.. I don´t know if it was a rhetoric awnser to tell me that I don´t have to use it, I would like if you could explain me better, sorry for my little wisdom – Eldestornillador Aug 20 '22 at 20:25
  • 1
    You are asking us to tell you if your project has any external dependencies which are only available on this particular third party website. Honestly, the answer is almost certainly no. But I can't go and perform your due diligence for you. Run [`gradle dependencies`](https://stackoverflow.com/a/21650904/2970947) and look through the list. – Elliott Frisch Aug 20 '22 at 20:32
  • @ElliottFrisch Thanks, I think I can imrpove my question to let you help me better. If I needed that "maven { url "https://jitpack.io" }" in my project before using jcenter(), my question is, if now I am using maveCentral(), is mavenCentral including "maven { url "https://jitpack.io" }" or it is totally indifferent if I am using jcenter or mavenCentral ? I mean, is "maven { url "https://jitpack.io" }" independent of jcenter() and mavenCentral()? – Eldestornillador Aug 20 '22 at 20:44
  • Yes. `mavenCentral()` is basically the same thing as `maven { url "https://repo.maven.apache.org/maven2/" }`. This is [documented](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.RepositoryHandler.html#org.gradle.api.artifacts.dsl.RepositoryHandler:mavenCentral()). – Elliott Frisch Aug 23 '22 at 00:03

1 Answers1

1

Or actually I should use the code line of maven jitpack (maven { url "https://jitpack.io" }") although now I am using mavenCentral() instead of jcenter()?

The choice of mavenCentral() versus jcenter() has nothing to do with jitpack.io and whether you should be using it as a repository.

You need a repository to obtain artifacts hosted by that repository. So, for example, you need the google() repository for most of Google's artifacts, such as the com.google.gms:google-services that you are using.

Whether you need jitpack.io will depend on whether you have any dependencies that come from that repository. We have no way of telling whether you do or you do not.

A comment on your question suggests removing it and seeing if your build breaks. That will not work immediately, as Gradle caches downloaded artifacts and usually works off of your cached copy. Your build would break in the future if you try updating the version of some dependency and none of the other repositories host that artifact (at least for that version).

The safest thing to do is to go through all your dependencies (everything listed in a dependencies closure in your project-level and module-level build.gradle files) and identify where they come from. Perhaps add comments to your Gradle files to help you keep track. If you find that none of your dependencies seem to come from jitpack.io, you can remove that repository.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Very well explained, but I have one question, what would happen if I use jtipack.io although I am not using any dependencies that come from jitpack.io? I mean, imagine that I am not sure if I am using dependencies that come from jitpack.io, would there be any problem if I am using maven { url "https://jitpack.io" } but I am not using any dependency from it? The only issue will be that it could be using extra space for my app but this wont affect if my app is working fine or not? – Eldestornillador Aug 20 '22 at 21:08
  • @Eldestornillador: "what would happen if I use jtipack.io although I am not using any dependencies that come from jitpack.io?" -- hopefully nothing. It may add a few hundred milliseconds to builds where you update dependencies, and [for security reasons it's better to remove unnecessary repositories](https://commonsware.com/blog/2021/02/20/using-repository-safelist-gradle.html). "it could be using extra space for my app" -- no, your APK/AAB will not be larger. – CommonsWare Aug 20 '22 at 21:15
  • 1
    Instead of using comments to say what repository a dependency belongs to, I would consider using content filters on the repositories to say what dependencies are in them. https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:declaring-repository-filter – Michael Krussel Aug 20 '22 at 21:26