Android buildscript repositories: jcenter VS mavencentral

JavaAndroidAndroid Gradle-PluginJcenterMaven Central

Java Problem Overview


The last time I used Android Studio, it generated .gradle files with mavencentral() buildscript repositories whereas now there's jcenter().

Could anyone explain the issues connected with this. Are there any other repos? When should we switch them? What impact do they have on projects, modules, libs? Any other essentials for Android developers?

Who's responsible for maintaining those repos?

Java Solutions


Solution 1 - Java

At Bintray I just rebloged a very detailed blog post describing the reasons why Google made this change. Here are the most important points:

Regarding performance improvements, couple of android developer advocates had faced/noticed the issue of huge indexing with maven central.

In the words of [Tor Norbye](https://plus.google.com/+TorNorbye/posts "https://plus.google.com/+TorNorbye/posts";): > I ran AndroidStudio with a brand new settings directory, so it went and connected maven central and downloaded an index of the available artifacts. > > Then I happened to look at the size of my directory. > > My ~/Library/Cache/AndroidStudioPreview is 1.5G, and 1.2G of those are taken by the “Maven” subdirectory. > > That’s ridiculous. We barely use the index at all. The primary use for it is the Dependency editor in the Project Structure Dialog, but we really don’t need to have a precomputed index for it. MavenCentral has a fast online JSON search we can use on demand when somebody searches for artifacts. In [https://android-review.googlesource.com/#/c/94843/](https://android-review.googlesource.com/#/c/94843/ "https://android-review.googlesource.com/#/c/94843/";) we added a lint check which checks whether the dependencies are up to date, and the search for a handful of artifacts is near instant. > > In short, we really don’t need the cache; it may help with code completion in .gradle and maven .pom files, but that’s not a super important usecase, and certainly not something all users should have to sacrifice 1.5G of download speed and diskspace to have the possibility of one day doing. Read more on: [The Maven index is huge!](https://code.google.com/p/android/issues/detail?id=72061 "https://code.google.com/p/android/issues/detail?id=72061";)

Also, you might find this [very short (1Q and 1A) discussion on Hacker News](https://news.ycombinator.com/item?id=8099840 "https://news.ycombinator.com/item?id=8099840";) interesting.


I am with JFrog, the company behind [tag:bintray] and [tag:artifactory], see my profile for details and links.

Solution 2 - Java

I was wondering the same, and I don't have a definitive answer but figured it might be worth sharing what (little) I'd learned. I found mention of the move from Maven Central to JCenter within one issue on Google Code, but didn't spot details about exactly when this happened - couldn't find mention in the recent changes list for Android Studio.

From reading up on JCenter, it is the repository behind Bintray, from the company JFrog (who I've come across before, and I guess that's where the 'J' comes from). According to the Bintray blog, Bintray is a superset of Maven Central, so if that's true there shouldn't be issues with missing dependencies, but I guess it's going to depend on exactly what you're using in your projects - you could always directly check the repos as both have nice easily-searchable websites. So for who maintains these repos, as best I know, it's up to the producers of the dependencies to add their dependencies to each repo, and up to the repo owner just to maintain the service.

In terms of when to switch it is difficult to work out. AOSP is still using Maven Central I think (from looking in Templates for New Android Application), but then that template is also still using a very old Gradle version (0.4) as well. There's a couple of issues about others having issues with dependencies from jcenter, but not really a lot reported, and it is possible that Google will switch again to some other repo before releasing AS final. If Maven Central is still working fine for you for now you could hold off switching until then especially if you're building large commercial solutions.

Solution 3 - Java

No matter what the default is in the build.gradle file - in a team based development effort you should really use a repository manager like Sonatype Nexus or JFrog Artifactory and not reference those upstream repositories directly.

This will allow you to save a lot of bandwidth, combine both and many other repositories and manage it all in your own network.

In terms of Maven Central vs JCenter. JCenter is effort from JFrog to embrace, extend (and exterminate?) Maven Central. Maven Central is the default repository in Maven, SBT and others, while Gradle has switched to JCenter. This is not surprising considering that JFrog and Gradleware work together as companies. Since the Android SDK uses Gradle as build system now, the move to JCenter was a logic next step.

JCenter itself is a thin veneer on top of Maven Central. It proxies it (more or less successfully) and adds additional components. Both are hosted on CDN networks and highly performant. Maven Central itself is the target for all Eclipse, Apache and most other open source projects and without it JCenter would be mostly empty.

Using either of them will work fine, but I would suggest to go straight to the source where you can and on top of that take control of it by using a repository manager. Nexus Open Source for example is free and has support for Maven repositories as used by Maven, Gradle, SBT, Ivy and others as well as NuGet, NPM and RubyGems support.

Disclaimer: I am the author of Repository Management with Nexus and Nexus trainer for Sonatype, the sponsor of the free Central Repository, the project lead of the Android Maven Plugin and have pushed some Android libraries to Central by rebuilding from AOSP.

Solution 4 - Java

http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

this article can answer you question .

> At first, Android Studio chose Maven Central as a default repository. Once you create a new project from old version of Android Studio, mavenCentral() would be automatically defined in build.gradle. > > But the big problem of Maven Central is it is not developer-friendly. It is surprisingly hard to upload the library to. To be able to do so, developer has to be at some level of geeky. And with some more reason for example a security concern and etc, Android Studio team decided to switch the default repository to jcenter instead as you can see that once you create a new project from latest version of Android Studio, jcenter() would be automatically defined instead of mavenCentral().

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJacobView Question on Stackoverflow
Solution 1 - JavaJBaruchView Answer on Stackoverflow
Solution 2 - JavaSGillView Answer on Stackoverflow
Solution 3 - JavaManfred MoserView Answer on Stackoverflow
Solution 4 - JavataotaoView Answer on Stackoverflow