94

Is there any difference between google() and maven { url 'https://maven.google.com' } in build.gradle file and if there is any, what is it?

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        // OR
        google()
    }
}
2
  • 5
    maven.google for android studio 2.3 and below versions. google() for android studio 3.0.0 and above. ( it's the same fuctionality)
    – user6490462
    Commented Sep 28, 2017 at 11:04
  • 1
    See here for more details.
    – Benjamin
    Commented Sep 28, 2017 at 11:16

3 Answers 3

112

The google() repository is a shortcut to Google's maven repository. It was introduced in Gradle 4.x+. The actual repository URL used is `"https://dl.google.com/dl/android/maven2/" as specified here. https://maven.google.com actually points to the same repository.

However, if you are planning to use the google() shortcut, you need Gradle 4.x+, Android Studio 3.x+ and Gradle plugin for Android 3.x+.

2
11

Small correction to the answer above. If you try to go to https://dl.google.com/dl/android/maven2/ it gives you a 404. The correct url to google maven repository is:

https://dl.google.com/dl/android/maven2/index.html or just https://maven.google.com

Here you can check all the supported libraries and the latest versions.

5
  • 1
    I think url may be changed beetwen gradle versions so this is the main purpose of shortcut
    – Vlad
    Commented Jul 17, 2018 at 16:25
  • 1
    This should have been posted as a comment to Jayson's answer. Commented Oct 1, 2018 at 18:39
  • dl.google.com/dl/android/maven2/index.html is also 404 now
    – drakeet
    Commented May 11, 2021 at 7:24
  • all these links are 404 now...
    – xiaoweiz
    Commented Dec 14, 2023 at 1:20
  • The links are working.
    – Sergio
    Commented Dec 19, 2023 at 14:25
1

When using gradle, you can mention multiple repositories which the build tool (gradle) uses to resolve dependencies mentioned in your project.

repositories {
    jcenter()
    maven { url 'https://maven.google.com' }
    google()
}

In the above scenario, you're mentioning 3 repositories which gradle can use to resolve dependencies—all of which are Maven repositories.

1. jcenter()

  • Means the JCenter Maven repository.
  • This is a shortcut available in later versions of gradle

2. { url 'https://maven.google.com' }

  • This means you are referring a Maven repo hosted at the URL which can be used by gradle to resolve the dependencies.
  • If you want, you can actually enter the URL for JCenter and this would be the same as mentioning jcenter() in the gradle file.

3. google()

  • This means the Google Maven repository
  • Similar to the notation maven(), this can be used in later versions of gradle only

Not the answer you're looking for? Browse other questions tagged or ask your own question.