# How to Include Guava in a Gradle Project: Complete Setup Guide

> Easily add Guava to your Gradle project. Learn the simple steps to include the Guava library using implementation or api configurations for JVM and Android development.

- Repository: [Google/guava](https://github.com/google/guava)
- Tags: how-to-guide
- Published: 2026-08-10

---

**Add Guava to your Gradle project by declaring `com.google.guava:guava:33.6.0-jre` (for JVM) or `33.6.0-android` (for Android) in your `dependencies` block using either `implementation` or `api` configuration.**

To include Guava in a Gradle project, you need to understand the library's dual-flavor publishing strategy and dependency scope selection. The **google/guava** repository distributes the library through Maven Central with distinct artifacts for standard Java and Android environments, each configured differently in your `build.gradle` or `build.gradle.kts` file.

## Understanding Guava's Maven Coordinates and Flavors

Guava publishes to Maven Central under the group ID **`com.google.guava`** and artifact ID **`guava`**. The project maintains two binary variants as defined in [`guava/pom.xml`](https://github.com/google/guava/blob/main/guava/pom.xml) and [`android/guava/pom.xml`](https://github.com/google/guava/blob/main/android/guava/pom.xml):

- **JRE flavor** (suffix `-jre`): Optimized for Java 8+ applications. This is the default choice for standard JVM projects.
- **Android flavor** (suffix `-android`): Compatibility build for Android projects or libraries targeting Android runtimes.

The version classifier determines which artifact Gradle resolves. For version `33.6.0`, you would specify either `33.6.0-jre` or `33.6.0-android` depending on your target platform.

## Adding Guava to Your Gradle Build

### Standard JVM Projects

For Java applications using the **JRE flavor**, add the dependency to your module's `build.gradle`:

```gradle
dependencies {
  implementation "com.google.guava:guava:33.6.0-jre"
}

```

In Kotlin DSL (`build.gradle.kts`):

```kotlin
dependencies {
  implementation("com.google.guava:guava:33.6.0-jre")
}

```

### Android Projects

Android modules must use the **Android flavor** to ensure compatibility with Android's runtime constraints. According to the [`android/guava/pom.xml`](https://github.com/google/guava/blob/main/android/guava/pom.xml) configuration:

```gradle
dependencies {
  implementation "com.google.guava:guava:33.6.0-android"
}

```

Or in Kotlin DSL:

```kotlin
dependencies {
  implementation("com.google.guava:guava:33.6.0-android")
}

```

## Implementation vs API Dependency Scope

When you include Guava in a Gradle project, you must choose between **`implementation`** and **`api`** configurations based on whether Guava types appear in your public signatures.

- **`implementation`**: Use this when Guava is an internal implementation detail. The dependency remains private to your module and is not exposed to consumers.
- **`api`**: Use this only when your public methods or classes expose Guava types (e.g., returning `ImmutableList` or accepting `CacheBuilder`). This follows Gradle's Java Library Plugin guidance on API-implementation separation.

As documented in the repository's [`README.md`](https://github.com/google/guava/blob/main/README.md) (lines 48-65) and the wiki guide [`UseGuavaInYourBuild.md`](https://github.com/google/guava/blob/main/UseGuavaInYourBuild.md), choosing the correct scope prevents dependency leakage and reduces compilation classpath bloat for downstream projects.

## Practical Code Examples

### Simple Java Library

For a basic Java library using Guava internally:

```gradle
plugins {
  id 'java-library'
}

repositories {
  mavenCentral()
}

dependencies {
  implementation "com.google.guava:guava:33.6.0-jre"
}

```

### Library Exposing Guava Types

When your library's public API includes Guava classes:

```gradle
plugins {
  id 'java-library'
}

repositories {
  mavenCentral()
}

dependencies {
  api "com.google.guava:guava:33.6.0-jre"
}

```

### Android Module Configuration

Complete Android setup using Kotlin DSL:

```kotlin
plugins {
  id("com.android.library")
  kotlin("android")
}

android {
  compileSdk = 34
  defaultConfig {
    minSdk = 24
  }
}

dependencies {
  implementation("com.google.guava:guava:33.6.0-android")
}

```

### Using Guava in Application Code

After adding the dependency, import and use Guava utilities:

```java
import com.google.common.collect.ImmutableList;

public class Example {
  public static void main(String[] args) {
    ImmutableList<String> list = ImmutableList.of("a", "b", "c");
    System.out.println(list);
  }
}

```

## Summary

- **Coordinates**: Guava uses `com.google.guava:guava` with either `-jre` or `-android` version suffixes as defined in [`guava/pom.xml`](https://github.com/google/guava/blob/main/guava/pom.xml) and [`android/guava/pom.xml`](https://github.com/google/guava/blob/main/android/guava/pom.xml).
- **Flavor Selection**: Use `-jre` for standard Java 8+ projects and `-android` for Android compatibility.
- **Scope Selection**: Use `implementation` for internal use only; use `api` only when exposing Guava types in your public API.
- **Repository**: Always declare `mavenCentral()` in your `repositories` block to resolve the artifacts.

## Frequently Asked Questions

### What is the difference between the JRE and Android flavors of Guava?

The **JRE flavor** (`guava-XX.X.X-jre.jar`) contains the complete Guava API optimized for standard Java 8+ virtual machines. The **Android flavor** (`guava-XX.X.X-android.jar`) omits or replaces APIs incompatible with Android's runtime, ensuring the library functions correctly on Android devices. Both artifacts share the same Maven coordinates but use different version classifiers.

### Should I use implementation or api for Guava dependencies?

Use **`implementation`** if your code uses Guava internally without exposing it in public method signatures. Use **`api`** only if your library's public interface accepts or returns Guava types (such as `ImmutableList` or `Optional`), forcing consumers to have Guava on their compilation classpath.

### Where is the official Gradle configuration documented?

The official snippets are located in the [`README.md`](https://github.com/google/guava/blob/main/README.md) file at lines 48-65 of the google/guava repository. Detailed guidance on dependency scope selection and build configuration is available in the wiki file [`UseGuavaInYourBuild.md`](https://github.com/google/guava/blob/main/UseGuavaInYourBuild.md).

### Can I use the JRE flavor in Android projects?

No. Android projects must use the **Android flavor** (`33.6.0-android` or similar) because the JRE flavor contains APIs and bytecode patterns incompatible with Android's runtime limitations. The [`android/guava/pom.xml`](https://github.com/google/guava/blob/main/android/guava/pom.xml) explicitly configures the Android-compatible build variant for this purpose.