通过Java访问工作表API时的NoSuchMethod
谷歌工作表快速启动 在遵循此链接的同时- 我明白了: 线程“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; 在 com.google.api.services.sheets.v4.sheets$Builder.setBatchPath(sheets.java:3143) 位于com.google.api.services.sheets.v4.sheets$Builder。(sheets.java:3122) 在 com.pansari.promotor.service.SheetQuickStart.main(SheetQuickStart.java:70) 规格:通过Java访问工作表API时的NoSuchMethod,java,google-sheets,google-sheets-api,google-workspace,Java,Google Sheets,Google Sheets Api,Google Workspace,谷歌工作表快速启动 在遵循此链接的同时- 我明白了: 线程“main”java.lang.NoSuchMethodError中出现异常: com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient$Builder.setBatchPath(Ljava/lang/String;)Lcom/google/api/client/googleapis/services/AbstractGoogleClient$Build
Java version (java -version) 1.8
OS Mac
POM变化:
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
有人能帮忙吗?新版本的JAR不包含您试图调用的方法。阅读这些软件包的API,了解它们的使用方式应与以前的版本有所不同。新版本的JAR不包含您试图调用的方法。阅读这些软件包的API,了解它们的使用方式应与以前的版本有所不同。在项目中使用这些依赖项:
<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>
com.google.api
.在项目中使用这些依赖项:
<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>
com.google.api
.我在这个问题上花了很多令人尴尬的时间,所以想留下一点小费。setBatchPath
的问题在于它是在谷歌api客户端1.23.0及更高版本中引入的。我在gradle.build文件中包含了谷歌api客户端的最新版本,但在项目的其他地方有覆盖,这迫使使用谷歌api客户端1.22.0,这破坏了代码
如果遇到此问题,请尝试以下操作:
- 例如,检查构建目录
build/dependency
中jar的版本
- 运行
gradle dependencyInsight--dependency com.google.api client
查看gradle在做什么
我的修复方法是将以下内容添加到库项目中的build.gradle和使用库的服务中
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'
}
}
我在这个问题上花了很多令人尴尬的时间,所以我想留下一点小费。setBatchPath
的问题在于它是在谷歌api客户端1.23.0及更高版本中引入的。我在gradle.build文件中包含了谷歌api客户端的最新版本,但在项目的其他地方有覆盖,这迫使使用谷歌api客户端1.22.0,这破坏了代码
如果遇到此问题,请尝试以下操作:
- 例如,检查构建目录
build/dependency
中jar的版本
- 运行
gradle dependencyInsight--dependency com.google.api client
查看gradle在做什么
我的修复方法是将以下内容添加到库项目中的build.gradle和使用库的服务中
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'
}
}
使用下面的命令检查项目的依赖关系树
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
检查google api客户端jar的不同版本,仅包括1.23.0版本,排除其他版本,如下所示。它应该会起作用
<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>
<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>
com.google.api
谷歌api服务数据流
v1b3-rev207-1.20.0
com.google.api-client
谷歌api客户端
使用下面的命令检查项目的依赖关系树
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
检查google api客户端jar的不同版本,仅包括1.23.0版本,排除其他版本,如下所示。它应该会起作用
<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>
<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>
com.google.api
谷歌api服务数据流
v1b3-rev207-1.20.0
com.google.api-client
谷歌api客户端
使用下面的命令检查项目的依赖关系树
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
包括1.23.0版本的google api客户端,不包括以下其他版本
com.google.api
谷歌api服务数据流
v1b3-rev207-1.20.0
com.google.api-client
谷歌api客户端
使用下面的命令检查项目的依赖关系树
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
包括1.23.0版本的google api客户端,不包括以下其他版本
com.google.api
谷歌api服务数据流
v1b3-rev207-1.20.0
com.google.api-client
谷歌api客户端