Java Android 构建脚本存储库:jcenter VS mavencentral
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24852219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android buildscript repositories: jcenter VS mavencentral
提问by Jacob
The last time I used Android Studio, it generated .gradle
files with mavencentral()
buildscript repositories whereas now there's jcenter()
.
我上次使用 Android Studio 时,它生成了.gradle
带有mavencentral()
buildscript 存储库的文件,而现在有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?
任何人都可以解释与此相关的问题。还有其他回购吗?我们什么时候应该切换它们?它们对项目、模块、库有什么影响?Android 开发人员还有其他必需品吗?
Who's responsible for maintaining those repos?
谁负责维护这些存储库?
回答by SGill
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.
我也在想同样的事情,我没有明确的答案,但我认为可能值得分享我所学到的(小)知识。我发现在 Google Code 上的一个问题中提到了从 Maven Central 到 JCenter 的迁移,但没有发现具体何时发生这种情况的详细信息 - 在 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.
从阅读 JCenter 来看,它是 Bintray 背后的存储库,来自 JFrog 公司(我以前遇到过,我猜这就是“J”的来源)。根据 Bintray 博客,Bintray 是 Maven Central 的超集,所以如果这是真的,那么应该不会出现缺少依赖项的问题,但我想这将取决于您在项目中使用的内容——您总是可以直接检查存储库,因为它们都有很好的易于搜索的网站。因此,对于谁维护这些存储库,据我所知,由依赖项的生产者将他们的依赖项添加到每个存储库,而由存储库所有者负责维护服务。
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.
至于何时切换,很难确定。我认为 AOSP 仍在使用 Maven Central(通过查看新 Android 应用程序的模板),但该模板也仍在使用非常旧的 Gradle 版本(0.4)。有一些关于其他人有来自 jcenter 的依赖问题的问题,但实际上并没有太多报告,而且谷歌可能会在发布 AS 最终版本之前再次切换到其他一些存储库。如果 Maven Central 现在对您来说仍然可以正常工作,那么您可以推迟切换,特别是如果您正在构建大型商业解决方案。
回答by Manfred Moser
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.
无论 build.gradle 文件中的默认值是什么 - 在基于团队的开发工作中,您应该真正使用像 Sonatype Nexus 或 JFrog Artifactory 这样的存储库管理器,而不是直接引用这些上游存储库。
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.
在 Maven Central 与 JCenter 方面。JCenter 是 JFrog 为拥抱、扩展(和消灭?)Maven Central 所做的努力。Maven Central 是 Maven、SBT 等的默认存储库,而 Gradle 已切换到 JCenter。考虑到 JFrog 和 Gradleware 作为公司一起工作,这并不奇怪。由于 Android SDK 现在使用 Gradle 作为构建系统,因此迁移到 JCenter 是下一步的逻辑。
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.
JCenter 本身是 Maven Central 之上的一个薄饰面。它代理它(或多或少成功)并添加其他组件。两者都托管在 CDN 网络上并且性能很高。Maven Central 本身是所有 Eclipse、Apache 和大多数其他开源项目的目标,如果没有它,JCenter 将大部分是空的。
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 Sourcefor 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.
使用它们中的任何一个都可以正常工作,但我建议直接访问源代码,并在此基础上使用存储库管理器控制它。例如,Nexus Open Source是免费的,并且支持 Maven、Gradle、SBT、Ivy 等使用的 Maven 存储库以及 NuGet、NPM 和 RubyGems 支持。
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.
免责声明:我是 Repository Management with Nexus 和 Sonatype 的 Nexus trainer 的作者,免费的 Central Repository 的赞助商,Android Maven Plugin 的项目负责人,并通过从 AOSP 重建将一些 Android 库推送到 Central。
回答by JBaruch
At Bintray I just rebloged a very detailed blog postdescribing the reasons why Google made this change. Here are the most important points:
在 Bintray,我刚刚转发了一篇非常详细的博客文章,描述了 Google 进行此更改的原因。以下是最重要的几点:
- 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 ofmavenCentral()
, 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.
- JCenter 是 Bintray 中的Java 存储库,它是世界上最大的 Java 和 Android OSS 库、包和组件的存储库。
- JCenter 中的所有内容都通过 CDN 提供,并具有安全的 HTTPS 连接。回到迁移时代(Android Studio 0.8),中央 maven 2 存储库仅支持 HTTP,不支持 HTTPS。参考:51.6.2。Maven 中央存储库。
jcenter()
是 的超集mavenCentral()
,包含许多额外的存储库和工件。- 在不同的场景和来自不同的国家,Bintray 比 Maven Central(例如来自以色列)更快。在其他情况下,它非常接近。由于 Maven Central 和 Bintray 使用不同的 CDN,这些 CDN 自适应地偏爱区域,这可能会改变为两种方式。
- Bintray 具有与传统 Maven Central 不同的包识别方法。这是一个重大而严重的安全问题。这很重要。
- 如果你真的需要将你的包送到 Maven Central(用于支持遗留工具),你也可以从 Bintray 完成,点击一个按钮,甚至自动完成。
Regarding performance improvements, couple of android developer advocates had faced/noticed the issue of huge indexing with maven central.
关于性能改进,一些 android 开发者拥护者已经面临/注意到 maven central 的巨大索引问题。
In the words of Tor Norbye:
用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 allusers 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!
我使用全新的设置目录运行 AndroidStudio,因此它连接了 maven central 并下载了可用工件的索引。
然后我碰巧查看了我的目录的大小。
我的 ~/Library/Cache/AndroidStudioPreview 是 1.5G,其中 1.2G 被“Maven”子目录占用。
这是荒谬的。我们几乎不使用索引。它的主要用途是项目结构对话框中的依赖项编辑器,但我们真的不需要为它预先计算索引。MavenCentral 有一个快速的在线 JSON 搜索,我们可以在有人搜索工件时按需使用。在https://android-review.googlesource.com/#/c/94843/ 中,我们添加了一个 lint 检查来检查依赖项是否是最新的,并且对少量工件的搜索几乎是即时的。
简而言之,我们真的不需要缓存;它可能有助于 .gradle 和 maven .pom 文件中的代码完成,但这不是一个非常重要的用例,当然也不是所有用户都应该牺牲 1.5G 的下载速度和磁盘空间才有可能有一天做的事情。阅读更多内容:Maven 索引很大!
Also, you might find this very short (1Q and 1A) discussion on Hacker Newsinteresting.
此外,您可能会发现关于 Hacker News 的这个非常简短(1Q 和 1A)的讨论很有趣。
I am with JFrog, the company behind bintrayand artifactory, see my profilefor details and links.
我与JFrog 合作,后者是bintray和artifactory背后的公司,有关详细信息和链接,请参阅我的个人资料。
回答by taotao
http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
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().
起初,Android Studio 选择 Maven Central 作为默认存储库。从旧版本的 Android Studio 创建新项目后,mavenCentral() 将自动在 build.gradle 中定义。
但是 Maven Central 的一个大问题是它对开发人员不友好。将库上传到其中非常困难。为了能够做到这一点,开发人员必须达到某种程度的极客水平。出于更多原因,例如安全问题等,Android Studio 团队决定将默认存储库切换为 jcenter,因为您可以看到,一旦您从最新版本的 Android Studio 创建新项目,就会自动定义 jcenter()而不是 mavenCentral()。