Skip to content

Instantly share code, notes, and snippets.

@caseykulm
Last active June 6, 2023 18:25
Show Gist options
  • Save caseykulm/8f229ef3d89dec02780ea880129bc75d to your computer and use it in GitHub Desktop.
Save caseykulm/8f229ef3d89dec02780ea880129bc75d to your computer and use it in GitHub Desktop.
Guava ListenableFuture Hell

Guava ListenableFuture Hell

Problem

Duplicate jar entry [com/google/common/util/concurrent/ListenableFuture.class]

Caused by having,

com.google.guava:listenablefuture:1.0

and

com.google.guava:guava:22.0-android

both exist as dependencies. This can sneakily happen if this situation happens because of transitive dependencies.

Solution

Explicitly depend on both the pre-27 version of Guava, and the empty version of ListenableFuture,

implementation "com.google.guava:guava:22.0-android"
implementation "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava"

The version number being 9999 is large enough for the default dependency resolution strategy to pick this one. This avoids duplicate by simply importing a version of the listenablefuture with nothing in it.

Notes

  • This is actually mentioned in the pom.xml file for listenablefuture version 9999.
  • This is not a problem if you can update Guava to version 27, in which case per the pom file, it will resolve itself (with Gradle's resolution strategy at least)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment