0
votes

Google sheet quickstart

While following this link - https://developers.google.com/sheets/api/quickstart/java I got this:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient$Builder.setBatchPath(Ljava/lang/String;)Lcom/google/api/client/googleapis/services/AbstractGoogleClient$Builder; at com.google.api.services.sheets.v4.Sheets$Builder.setBatchPath(Sheets.java:3143) at com.google.api.services.sheets.v4.Sheets$Builder.(Sheets.java:3122) at com.pansari.promoter.service.SheetQuickStart.main(SheetQuickStart.java:70)

Specifications:

Java version (java -version) 1.8
OS Mac

POM changes:

com.google.apis
google-api-services-sheets
v4-rev516-1.23.0


com.google.api-client
google-api-client
1.23.0


com.google.oauth-client
google-oauth-client-jetty
1.23.0

Can anyone help?

5

5 Answers

2
votes

I spent an embarrassing amount of time on this problem, so wanted to leave a tip. The issue with setBatchPath is that it was introduced in google-api-client 1.23.0 and later. I was including the latest builds of google-api-client in my gradle.build file, BUT there were overrides elsewhere in the project that forced the usage of google-api-client 1.22.0 which was breaking the code.

If you're having this problem, try the following:

  • Check what version of jar is in your build directory build/dependency for example.
  • Run gradle dependencyInsight --dependency com.google.api-client to see what gradle is doing if you're doing it

The fix for me was adding the following to my build.gradle in the library project and the service that was consuming the library.

dependencyManagement {
    dependencies{
        dependency 'com.google.apis:google-api-services-sheets:v4-rev607-1.25.0'
        dependency 'com.google.api-client:google-api-client:1.25.0'
    }
}
0
votes

The new version of your jars do not contain the method you are trying to call. Read the API for these packages to see how they should be used differently from the previous versions.

0
votes

Use these dependencies in your project:

<dependencies>
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-sheets</artifactId>
            <version>v4-rev1-1.21.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client</artifactId>
            <version>1.30.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client-java6</artifactId>
            <version>1.30.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client-jetty</artifactId>
            <version>1.30.4</version>
        </dependency>
    </dependencies>

You can check all the current official dependencies versions by Google HERE.

0
votes

Check your dependency tree of your project using below command.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=truemvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true

Check different versions of google-api-client jar is and include only 1.23.0 version and exclude other version as below. It should work.

<dependency>
     <groupId>com.google.apis</groupId>
     <artifactId>google-api-services-dataflow</artifactId>
     <version>v1b3-rev207-1.20.0</version>
     <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
        </exclusion>
     </exclusions> 
    </dependency>
0
votes

Check dependency tree of your project using below command

mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=truemvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true

and include 1.23.0 version of google-api-client and exclude other versions as below.

<dependency>
     <groupId>com.google.apis</groupId>
     <artifactId>google-api-services-dataflow</artifactId>
     <version>v1b3-rev207-1.20.0</version>
     <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
        </exclusion>
     </exclusions> 
    </dependency>