HK15
HK15

Reputation: 807

NoSuchMethodError in com.google.api.client library

I'm trying to use the Google Cloud Storage SDK for Java into my Spring application.

Using Maven I've added it to my dependencies:

<dependency>
   <groupId>com.google.cloud</groupId>
   <artifactId>google-cloud-storage</artifactId>
   <version>1.31.0</version>
</dependency> 

Then I try to initialize the Storage client with:

 client = StorageOptions.newBuilder()
                    .setCredentials(ServiceAccountCredentials.fromStream(new ClassPathResource("/my/path/to.json").getInputStream()))
                    .build()
                    .getService();

but an error occurs

java.lang.NoSuchMethodError: com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient$Builder.setBatchPath

I've noticed that in my google-api-client-1.23.0.jar libray loaded as dependency no setBatchPath was present.

I've tried to find the issue browsing on web but without fortune. I cannot understand which library (and version) I need to install in order to make it works.

Upvotes: 2

Views: 8615

Answers (2)

HK15
HK15

Reputation: 807

Eventually I solved, there was a library duplication between my Web Application and Its Business Layer Jar component (I have a multi-module Project).

What I cannot understand is why there was a call to a non-existing method (AbstractGoogleJsonClient$Builder.setBatchPath) that was solved in this way.

In google-api-client-1.20.0.jar that method does not exists nor in google-api-client-1.23.0.jar

Upvotes: 4

Kohei TAMURA
Kohei TAMURA

Reputation: 5132

Try reading this, and then you may be able to work around the error.

Upvotes: 0

Related Questions