70

Should I be worried about JCenter being deprecated?

Why should I migrate my libraries from JCenter to other Maven repositories?

Can I continue to use jcenter() in my Gradle build script?

Mahozad
  • 18,032
  • 13
  • 118
  • 133

10 Answers10

99

Replace

jcenter()

with this:

mavenCentral()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Umar Ata
  • 4,170
  • 3
  • 23
  • 35
  • 53
    Note that the library should be available on Maven Central repository. Otherwise, simply replacing `jcenter()` with `mavenCentral()` will do no good. – Mahozad May 11 '21 at 11:33
  • 2
    @Mahozad True, in some cases, we'll need to go to developer's site and copy the maven line that usually looks like this: `maven {url 'https://my.library-url.com/'}` – cmak Jan 20 '22 at 17:44
32

Please see the new answer.

Summary: After February 1st, 2022 jcenter() will not work anymore.

According to this Gradle blog post:

Gradle 7.0 will deprecate the use of jcenter() to resolve dependencies.
You will still be able to use JCenter as a repository, but Gradle will emit a warning.
The jcenter() method will be removed in the next major release.

Gradle has no inherent tie to JCenter or Maven Central, so you can always switch to any other repository of your choice.

And according to Android Developers:

JFrog, the company that maintains the JCenter artifact repository used by many Android projects, recently announced the deprecation and upcoming retirement of JCenter.
According to the announcement, JCenter will allow downloads of existing artifacts until February 1, 2022.

Developers who publish artifacts on JCenter should start migrating packages to a new host, such as Maven Central.

So, just make sure that the authors provide their library in other repositories and then update your build scripts to enable downloading from those repositories.
For example, in Gradle use mavenCentral() function to enable getting dependencies from Maven Central repository.

Mahozad
  • 18,032
  • 13
  • 118
  • 133
  • 4
    Wrong. "May 1st, 2021 Bintray services will no longer be available. GoCenter, and ChartCenter services will no longer be available to non-Artifactory clients. (ConanCenter and JCenter are not affected)." and "UPDATE 4/27/2021: We listened to the community and will keep JCenter as a read-only repository indefinitely. Our customers and the community can continue to rely on JCenter as a reliable mirror for Java packages." – The incredible Jan Jul 19 '21 at 07:56
29

The latest update as mentioned here in JFrog's website is the following:

UPDATE 4/27/2021: We listened to the community and will keep JCenter as a read-only repository indefinitely. Our customers and the community can continue to rely on JCenter as a reliable mirror for Java packages.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    JCenter itself may keep working, but it will get deprecated and removed from various tools, like Gradle. So effectively, most people need to stop using it. – Stan Dec 17 '21 at 13:54
  • 1
    @Stan how to stop? I am using shadow plugin for Gradle, and it is only on jcenter – Nhân Trần Jun 13 '22 at 06:52
  • > jcenter() method will be removed in the next major release This is still applicable, right? How it can be replaced? – reducing activity Jun 19 '22 at 14:44
  • Best case scenario - find your dependencies on maven or another place. Worst case - they're only on jcenter (and the projects are not active), so you have to either move them yourself / fork them / download and the source directly / etc... – Stan Aug 09 '22 at 19:27
18

Replace jcenter() by:

gradlePluginPortal()
mavenCentral()
  • 3
    The Gradle Plugin Portal implicitly mirrors JCenter currently. If you’re using the Plugin Portal (via gradlePluginPortal() or the URL plugins.gradle.org/m2) to resolve your application’s dependencies, you may be relying on JCenter. You should avoid using the Plugin Portal as a repository, except for Gradle plugin projects. https://blog.gradle.org/jcenter-shutdown – togikan Jul 23 '21 at 12:26
  • @togikan It's absolutely gradle plugin projects, as it's default for android projects. Or maybe not if the owner of this question used something else. –  Jul 24 '21 at 13:18
  • "The Gradle Plugin Portal implicitly mirrors JCenter currently" is there some info how long they will be definitely doing this? – reducing activity Jun 19 '22 at 14:43
9

You have to change

jcenter()

with

mavenCentral()

moreover you have to set one or more repository urls:

repositories {
    mavenCentral()
    maven {
        url = "https://repo1.maven.org/maven2/"
    }
    maven {
        url "https://repo.spring.io/release"
    }
    maven {
        url "https://repository.jboss.org/maven2"
    }
    maven {
        url 'https://repo.jenkins-ci.org/public/'
    }
}
N3tMaster
  • 398
  • 3
  • 13
2

Actually, developers should port their libraries to Maven or Google. In this case, jCenter() can be removed from Gradle.

A problem occurs when old libraries are no longer maintained or the developers are retired.

There are only two possibilities:

a) search e.g. in Maven for a similar library.

b) Download the corresponding source code from GitHub and create your own local library from it.

As of 2022-02-01 JCenter is definitely down.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
guenter47
  • 457
  • 5
  • 13
1

In my case i have followed these steps to get it done :

  1. Place mavenCentral() before jcenter()
  2. Upgrade gradle using Android Studio Upgrade Assistant (in my case upgraded to 7.0.3)
  3. Install NDK (Side by Side) through plugins (Android Studio)
  4. Clean & Rebuild project
Ayoub EL ABOUSSI
  • 636
  • 6
  • 13
0

I tried everything but nothing worked, then add a new maven repository by hand and now it's working.

repositories {
 // ...
 maven { url 'https://repo.gradle.org/gradle/libs-releases/' }
}
Mahozad
  • 18,032
  • 13
  • 118
  • 133
Bob
  • 71
  • 4
0

Nothing works anymore. We can use aliyun.com for the time being.

Use it like this in the top level build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/apache-snapshots' }
    }
    dependencies {
        ***
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/apache-snapshots' }
    }
}
M D P
  • 4,525
  • 2
  • 23
  • 35
0

For those still looking for an answer, I found the repository setting needed to be at the top of build script or the change didn't get picked up.

buildscript {
  repositories {
    mavenCentral()
  }
}

This works for me.

Stuart McIntyre
  • 918
  • 6
  • 8