NoSuchMethodError with Guava , GCP Cloud Storage & Datastax

Viewed 303

java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J

Getting above error msg , when using Guava - 18.0v with Cloud Storage - 2.2.2v:

 <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId>
      <version>2.2.2</version>
 </dependency>
 <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>18.0</version>
 </dependency>
 <dependency>
      <groupId>com.datastax.cassandra</groupId>
      <artifactId>cassandra-driver-core</artifactId>
      <version>3.2.0</version>
 </dependency>

If I use Guava - 23v with Datastax -3.2.0v I'm getting below error msg:

java.lang.NoClassDefFoundError: com/google/common/util/concurrent/FutureFallback

so Cloud storage needs Guava version above 20 , but DataStax needs version below 20 , so either thing is working at a time but I want both the things.

My code:

 StorageOptions options = StorageOptions.newBuilder()
      .setProjectId(PROJECT_ID)
      .setCredentials(GoogleCredentials
           .fromStream(new FileInputStream(PATH_TO_JSON_KEY))).build();
 Storage storage = options.getService();
 Blob blob = storage.get(BUCKET_NAME, OBJECT_NAME);
 ReadChannel r = blob.reader();
2 Answers

3.2.0 seems like a very old version of Cassandra driver from 2017 -- try upgrading to the latest in this major version, 3.11.0.

It also looks like the driver switched packages to com.datastackx.oss:java-driver-core and moved to the major version 4.x.

Tried to reproduce your error using the code and dependencies you have provided.

enter image description here

and was able to resolve the issue by using these version.

<dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId>
      <version>2.2.2</version>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>20.0</version>
    </dependency>
     <dependency>
      <groupId>com.datastax.cassandra</groupId>
      <artifactId>cassandra-driver-core</artifactId>
      <version>3.11.0</version>
    </dependency>

Output: enter image description here

It is also advisable to use the latest version of DataStax when you're using Guava 20.0 and above.

Related