JCenter deprecation; impact on Gradle and Android
Asked Answered
E

11

74

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?

Erwin answered 16/3, 2021 at 8:39 Comment(1)
B
31

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.

Brisson answered 29/6, 2021 at 10:15 Comment(4)
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.Barrybarrymore
@Barrybarrymore how to stop? I am using shadow plugin for Gradle, and it is only on jcenterRochellerochemont
> jcenter() method will be removed in the next major release This is still applicable, right? How it can be replaced?Electroform
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...Barrybarrymore
F
103

Replace

jcenter()

with this:

mavenCentral()
Fir answered 11/5, 2021 at 7:42 Comment(2)
Note that the library should be available on Maven Central repository. Otherwise, simply replacing jcenter() with mavenCentral() will do no good.Erwin
@Erwin 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/'}Shoebill
E
34

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.

Erwin answered 16/3, 2021 at 8:39 Comment(1)
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."Boogiewoogie
B
31

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.

Brisson answered 29/6, 2021 at 10:15 Comment(4)
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.Barrybarrymore
@Barrybarrymore how to stop? I am using shadow plugin for Gradle, and it is only on jcenterRochellerochemont
> jcenter() method will be removed in the next major release This is still applicable, right? How it can be replaced?Electroform
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...Barrybarrymore
E
20

Replace jcenter() by:

gradlePluginPortal()
mavenCentral()
Evanston answered 4/7, 2021 at 11:10 Comment(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. blog.gradle.org/jcenter-shutdownBeveridge
@Beveridge 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.Evanston
"The Gradle Plugin Portal implicitly mirrors JCenter currently" is there some info how long they will be definitely doing this?Electroform
L
12

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/'
    }
}
Leadsman answered 13/1, 2022 at 10:3 Comment(4)
Thank you. After many other answers, this one worked - probably because it has the correct mirrors that has the older versions of dependencies my project is still using. I only want it to get it working. I can't upgrade everything...Fid
is mavenCentral mirroring entire jcenter?Electroform
@reducingactivity : yes it should beLeadsman
@reducingactivity noMasochism
N
1

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.

Neubauer answered 5/5, 2021 at 15:35 Comment(6)
Do you have any tips on option B? I program for a barcode scanner that runs Android and I already am pretty sure the manufacturer's devs are gonna be late to this party.Anthesis
Another answer contradicts the statement in the last paragraph.Karlykarlyn
As of 2022-02-01 JCenter is definitely down - no, it's not.Winstonwinstonn
"no, it's not." ? - what is javaxian trying to tell us? See: developer.android.com/build/jcenter-migrationNeubauer
JCenter is not down, it's switched to the read-only mode, you can still reach it by using maven { url = uri("https://jcenter.bintray.com") }Winstonwinstonn
@Winstonwinstonn this must be an answer.Fission
A
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
Algarroba answered 20/1, 2022 at 17:37 Comment(0)
G
1

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.

Growler answered 16/11, 2022 at 3:11 Comment(0)
M
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/' }
}
Madeline answered 12/5, 2022 at 12:26 Comment(0)
M
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' }
    }
}
Masochism answered 2/11, 2022 at 4:1 Comment(0)
F
0

In my case 2024, I didn't seen the "jcenter()" on the "build.gradle" and the problem still shown ... So first thing I had RUN:

E:\FlutterProjects\project_name\android> ./gradlew build --warning-mode all

> Configure project :modal_progress_hud_nsn
The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 8.0. JFrog announced JCenter's sunset in February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/7.4/userguide/upgrading_version_6.html#jcenter_deprecation
        at build_1uqqsrqg2umy8x9ryoqs90h6c$_run_closure1$_closure2.doCall(C:\Users\ADMIN\AppData\Local\Pub\Cache\hosted\pub.dev\modal_progress_hud_nsn-0.1.0-nullsafety-1\android\build.gradle:8)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.2.1) was tested up to compileSdk = 32

This warning can be suppressed by adding
    android.suppressUnsupportedCompileSdk=33
to this project's gradle.properties

The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdk = 33

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':flutter_plugin_android_lifecycle:test'.
> Could not create task ':flutter_plugin_android_lifecycle:testDebugUnitTest'.
   > this and base files have different roots: E:\FlutterProjects\project_name\build\flutter_plugin_android_lifecycle and C:\Users\ADMIN\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_plugin_android_lifecycle-2.0.6\android.

Now solving the problem:

  • Change dependency version "modal_progress_hud_nsn" from modal_progress_hud_nsn: ^0.1.0-nullsafety-1 to modal_progress_hud_nsn: ^0.4.0 Or higher.

  • Add android.suppressUnsupportedCompileSdk=33 to "android/gradle.properties"

Now the problem is:

PS E:\FlutterProjects\project_name\android> ./gradlew build --warning-mode all

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':flutter_plugin_android_lifecycle:test'.
> Could not create task ':flutter_plugin_android_lifecycle:testDebugUnitTest'.
   > this and base files have different roots: E:\FlutterProjects\project_name\build\flutter_plugin_android_lifecycle and C:\Users\ADMIN\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_plugin_android_lifecycle-2.0.6\android.
  • Run "flutter clean"
  • Do the Gradle sync without flutter pub get and make necessary changes to native - android code.
  • Run "flutter pub get"
  • Run the app.

We recommend using a newer Android Gradle plugin to use compileSdk = 33

Could not create task ... this and base files have different roots

Fascist answered 10/2 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.