Android buildscript repositories: jcenter VS mavencentral

爱⌒轻易说出口 提交于 2019-11-26 12:19:51

问题


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?


回答1:


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

  • JCenter is a Java repository in Bintray, which is the largest repo in the world for Java and Android OSS libraries, packages and components.
  • All the content in JCenter is served over a CDN, with a secure HTTPS connection. Back in the time of the migration (Android Studio 0.8) The central maven 2 repository was HTTP only and HTTPS wasn't supported. Reference: 51.6.2. Maven central repository.
  • jcenter() is a superset of mavenCentral(), that encompasses many additional repositories and artifacts.
  • In different scenarios and from different countries Bintray is faster than Maven Central (e.g. from Israel). In others it is very close. Since Maven Central and Bintray use different CDNs which adaptively favor regions, this might change to both ways.
  • Bintray has a different approach to package identification than the legacy Maven Central. This is a big and serious security matter. It is important.
  • If you really need to get your package to Maven Central (for supporting legacy tools) you can do it from Bintray as well, in a click of a button or even automatically.

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:

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/ 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!

Also, you might find this very short (1Q and 1A) discussion on Hacker News interesting.


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




回答2:


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.




回答3:


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.




回答4:


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().



来源:https://stackoverflow.com/questions/24852219/android-buildscript-repositories-jcenter-vs-mavencentral

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!