Setup Instructions

  • The Google API Client Library for Java and its dependencies can be downloaded as a zip file or managed using Maven.

  • Specific jar files are required for different Java platforms, including Android, Google App Engine, Servlet, and Generic Java applications.

  • For Android development, using the Google Play Services library is recommended if the desired Google API is included there.

  • The library is organized into nine modules, each with specific dependencies and Maven usage instructions.

Use a dependency manager such as Maven or Gradle to add the Google API Client Library for Java to your project from the Maven Central repository.

Generated libraries for Google APIs

To call a specific Google API, add the generated library for that API from google-api-java-client-services. Each generated library already depends on com.google.api-client:google-api-client, and its README provides the exact Maven and Gradle coordinates for that API version.

Maven

The Google API Client Library for Java is published on Maven Central. The Maven groupId for all artifacts in this library is com.google.api-client.

To ensure compatible versions across google-api-client, google-http-client, google-oauth-client, and google-auth-library-java, import the Google Cloud Libraries BOM (com.google.cloud:libraries-bom) in the dependencyManagement section of your pom.xml. Replace LATEST_BOM_VERSION with the latest version of com.google.cloud:libraries-bom from Maven Central:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>LATEST_BOM_VERSION</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

Then declare the artifacts you need in <dependencies> without specifying individual versions:

<dependencies>
  <dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
  </dependency>
  <dependency>
    <groupId>com.google.auth</groupId>
    <artifactId>google-auth-library-oauth2-http</artifactId>
  </dependency>
</dependencies>

If you prefer not to import com.google.cloud:libraries-bom, specify the latest artifact versions from Maven Central directly: com.google.api-client:google-api-client and com.google.auth:google-auth-library-oauth2-http.

Gradle

In Gradle 5.0 or later, import com.google.cloud:libraries-bom as a platform dependency in your build.gradle file and omit versions on the individual dependencies. Replace LATEST_BOM_VERSION with the latest version of com.google.cloud:libraries-bom from Maven Central:

repositories {
  mavenCentral()
}

dependencies {
  implementation platform('com.google.cloud:libraries-bom:LATEST_BOM_VERSION')
  implementation 'com.google.api-client:google-api-client'
  implementation 'com.google.auth:google-auth-library-oauth2-http'
}

If you prefer not to import com.google.cloud:libraries-bom, specify the latest artifact versions directly from Maven Central (google-api-client and google-auth-library-oauth2-http):

dependencies {
  implementation 'com.google.api-client:google-api-client:LATEST_API_CLIENT_VERSION'
  implementation 'com.google.auth:google-auth-library-oauth2-http:LATEST_AUTH_VERSION'
}

Authentication dependencies

For authentication (such as Application Default Credentials using com.google.auth.oauth2.GoogleCredentials and com.google.auth.http.HttpCredentialsAdapter), use the Google Auth Library for Java:

  • com.google.auth:google-auth-library-oauth2-http provides GoogleCredentials, HttpCredentialsAdapter, and OAuth 2.0 credential implementations.
  • com.google.auth:google-auth-library-credentials provides the base Credentials interface and is brought in transitively by google-auth-library-oauth2-http.

Although google-api-client brings in google-auth-library-oauth2-http, google-auth-library-credentials, and google-oauth-client as transitive dependencies, declare com.google.auth:google-auth-library-oauth2-http explicitly whenever your code imports com.google.auth.* classes and manage its version with com.google.cloud:libraries-bom (or com.google.auth:google-auth-library-bom). Without a BOM, google-api-client can resolve an older transitive version of google-auth-library-oauth2-http.

Modules

This library is composed of nine modules (when using com.google.cloud:libraries-bom, omit <version> on all modules except google-api-client-apache-v5):

google-api-client

The Google API Client Library for Java (google-api-client) is designed to be compatible with Java 8 and higher, including Android.

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client'

On Android, if you are developing for a Google API included in the Google Play services library, use Google Play services instead. Otherwise, exclude Apache HTTP Client if it conflicts with your Android build:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
    </exclusion>
  </exclusions>
</dependency>

google-api-client-android

Extensions to the Google API Client Library for Java (google-api-client-android) support Android applications.

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-android</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-android'

google-api-client-servlet

Servlet and JDO extensions to the Google API Client Library for Java (google-api-client-servlet) support Java servlet web applications.

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-servlet</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-servlet'

google-api-client-appengine

Google App Engine extensions to the Google API Client Library for Java (google-api-client-appengine) support Google App Engine applications.

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-appengine</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-appengine'

google-api-client-gson

Gson extensions to the Google API Client Library for Java (google-api-client-gson).

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-gson</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-gson'

google-api-client-jackson2

Jackson 2 extensions to the Google API Client Library for Java (google-api-client-jackson2).

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-jackson2</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-jackson2'

google-api-client-protobuf

Protocol buffer extensions to the Google API Client Library for Java (google-api-client-protobuf).

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-protobuf</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-protobuf'

google-api-client-xml

XML extensions to the Google API Client Library for Java (google-api-client-xml).

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-xml</artifactId>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-xml'

google-api-client-apache-v5

Apache HTTP Client 5 transport extension (google-api-client-apache-v5) for creating an HttpTransport backed by Apache HTTP Client 5. Prefer this module over GoogleApacheHttpTransport in google-api-client, which uses the end-of-life Apache HTTP Client 4.

Maven:

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-apache-v5</artifactId>
  <version>LATEST_VERSION</version>
</dependency>

Gradle:

implementation 'com.google.api-client:google-api-client-apache-v5:LATEST_VERSION'

Download the library with dependencies

If you are not using Maven or Gradle, you can download the latest assembly zip file from the downloads page and extract it on your computer. The zip file contains the class JAR files (in libs/) and source JAR files (in libs-sources/) for each artifact and its dependencies, including google-auth-library-oauth2-http and google-auth-library-credentials. See the bundled readme.html file and dependencies/ directory for dependency graphs and licenses.