Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
783 views
in Technique[技术] by (71.8m points)

maven - Difference among mavenCentral(), jCenter() and mavenLocal()?

Actually, I am studying on build.gradle file. In some cases, I got that sometimes they are using mavenCentral(), jCenter() and mavenLocal() in repositories section. Sometimes they also using URL. So some question arises in my mind?

i) Difference among mavenCentral(), jCenter() and mavenLocal()?

ii) Which one should I use most?

iii) Is there any performance related issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually, all 3 are Maven repository. We use these maven repositories to our build by using its URL address or its location in the local file system.

By using URL:

repositories {
    maven { url("https://plugins.gradle.org/m2/") }
}

By using local file system:

repositories {
    maven { url '../maven-repo' }
}

Gradle has three “aliases” which we can use when we are adding Maven repositories to our build. These aliases are:

  1. mavenCentral():

The mavenCentral() alias means that dependencies are fetched from the central Maven 2 repository.

repositories {
    mavenCentral()
}

The URL used to access this repository is https://repo.maven.apache.org/maven2/. The name of the repository is MavenRepo.

  1. jcenter():

The jcenter() alias means that dependencies are fetched from the Bintray’s JCenter Maven repository

  1. mavenLocal():

The mavenLocal() alias means that dependencies are fetched from the local Maven repository.

Resource Link:

  1. Gradle: Dependency Management

  2. Maven RepositoryHandler


Jcenter vs. mavenCentral

jcenter() and mavenCentral() is a repository for the Gradle plugin in Android Studio

Earlier versions of Android Studio used mavenCentral(), and after some time, it switched to jcenter.

This is because jcenter() is superior to mavenCentral() in terms of performance and memory footprint:

  • Jcenter is the world's largest Java repository
  • Jcenter through the CDN service, using the https protocol, highly secured, and Android Studio 0.8 version mavenCentral() using the http protocol
  • Jcenter is a superset of mavenCentral, including many additional jars
  • Jcenter performance is better than mavenCentral
  • mavenCentral will automatically download many IDE-related indexes, and these are used less often which are not required.

Resource Link: https://www.jianshu.com/p/bce437eeb3d3


Last Update: Into the Sunset on May 1st: Bintray, JCenter, GoCenter, and ChartCenter

enter image description here

Update: 24-02-2021 of Android Developers Page:

enter image description here

Announcement Link: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

Maven Central Link: https://maven.apache.org/repository/index.html

Work Around:

repositories {
    mavenLocal()
    
//  jcenter()       // <- remove it
    mavenCentral()  // <- add it
    
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "https://repo.spring.io/plugins-release/" }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...