Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
949 views
in Technique[技术] by (71.8m points)

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

I'm getting this "java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J" error while using ServiceCredentials.fromStream() method. Anyone here faced this and know a fix? TIA

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[title]</groupId>
<artifactId>calendar-event-consumer</artifactId>
<version>0.1</version>
<name>${project.artifactId}</name>
<description>Service that listens for events in a queue to push them 
to an external API</description>
<inceptionYear>2017</inceptionYear>

<packaging>jar</packaging>

<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.11.5</scala.version>
<scala.compat.version>2.11</scala.compat.version>
</properties>

<dependencies>
<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-library</artifactId>
  <version>${scala.version}</version>
</dependency>

<!-- Test -->
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.specs2</groupId>
  <artifactId>specs2-core_${scala.compat.version}</artifactId>
  <version>2.4.16</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest_${scala.compat.version}</artifactId>
  <version>2.2.4</version>
  <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency>
  <groupId>com.rabbitmq</groupId>
  <artifactId>amqp-client</artifactId>
  <version>4.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.21</version>
</dependency>

<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback- 
classic -->
<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.2.3</version>
</dependency>

<!--JSON parsing-->
<dependency>
  <groupId>org.json4s</groupId>
  <artifactId>json4s-native_2.11</artifactId>
  <version>3.5.3</version>
</dependency>

<!--Google Calendar API-->
<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client</artifactId>
  <version>1.22.0</version>
</dependency>
<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-jetty</artifactId>
  <version>1.22.0</version>
</dependency>
<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-calendar</artifactId>
  <version>v3-rev254-1.22.0</version>
</dependency>
<dependency>
  <groupId>com.google.auth</groupId>
  <artifactId>google-auth-library-oauth2-http</artifactId>
  <version>0.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>23.0</version>
</dependency>

<!--Slick -->
<dependency>
  <groupId>com.typesafe.slick</groupId>
  <artifactId>slick_2.11</artifactId>
  <version>3.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java - 
->
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>6.0.6</version>
</dependency>
<dependency>
  <groupId>com.typesafe</groupId>
  <artifactId>config</artifactId>
  <version>1.3.1</version>
</dependency>
<dependency>
  <groupId>com.typesafe.slick</groupId>
  <artifactId>slick-hikaricp_2.11</artifactId>
  <version>3.2.1</version>
</dependency>



</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
  <plugin>
    <!-- see http://davidb.github.com/scala-maven-plugin -->
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
      <args>
        <arg>-Xmax-classfile-name</arg>
        <arg>128</arg>
      </args>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>compile</goal>
          <goal>testCompile</goal>
        </goals>
        <configuration>
          <args>
            <arg>-deprecation</arg>
            <arg>-dependencyfile</arg>

<arg>${project.build.directory}/.scala_dependencies</arg>
          </args>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
      <useFile>false</useFile>
      <disableXmlReport>true</disableXmlReport>
      <!-- If you have classpath issue like NoDefClassError,... -->
      <!-- useManifestOnlyJar>false</useManifestOnlyJar -->
      <includes>
        <include>**/*Test.*</include>
        <include>**/*Suite.*</include>
      </includes>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
      <execution>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>maven</executable>
      <workingDirectory>/tmp</workingDirectory>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
      <archive>
        <manifest>
          <mainClass>com.qpercom.App</mainClass>
        </manifest>
      </archive>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>
</project>

Error Log:

17:40:54.163 [pool-1-thread-3] INFO c.q.c.rabbitmq.RabbitMQEventConsumer - Received message of type class com.qpercom.model.CreateOrUpdateEventMessage on event (185, omis19demo) 17:40:54.626 [pool-1-thread-3] INFO com.zaxxer.hikari.HikariDataSource - googleApiDb - Started. 17:40:55.553 [pool-1-thread-3] INFO c.q.c.google.GoogleCalendarPusher - Creating event in Google Calendar 17:40:55.690 [pool-1-thread-3] INFO c.q.c.google.GoogleCalendarPusher - Instantiating Google Calendar Service... 17:40:57.063 [pool-1-thread-3] ERROR c.q.c.rabbitmq.RabbitMQEventConsumer - Failed pushing event. The message has been re-queued. Trace of exception: java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J 17:40:57.065 [pool-1-thread-3] ERROR c.r.c.impl.ForgivingExceptionHandler - Consumer com.qpercom.consumer.rabbitmq.RabbitMQEventConsumer$$anon$1@56acb716 (amq.ctag-CJwhF_0CeOmwK1kBKrQLXw) method handleDelivery for channel AMQChannel(amqp://zdMBDgTdd9fMMJft@3.249.159.145:5672/,1) threw an exception for channel AMQChannel(amqp://zdMBDgTdd9fMMJft@3.249.159.145:5672/,1) java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J at com.google.api.client.http.ConsumingInputStream.close(ConsumingInputStream.java:40) at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._closeInput(UTF8StreamJsonParser.java:237) at com.fasterxml.jackson.core.base.ParserBase.close(ParserBase.java:345) at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.close(UTF8StreamJsonParser.java:808) at com.google.api.client.json.jackson2.JacksonParser.close(JacksonParser.java:50) at com.google.api.client.json.JsonParser.parse(JsonParser.java:365) at com.google.api.client.json.JsonParser.parse(JsonParser.java:337) at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79) at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73) at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:444) at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:447) at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:157) at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:145) at com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadata(ServiceAccountCredentials.java:603) at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:91) at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:88) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:300) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) at com.qpercom.calendar.google.GoogleCalendarPusher.colorIdFor(GoogleCalendarPusher.scala:145) at com.qpercom.calendar.google.GoogleCalendarPusher.doCreate(GoogleCalendarPusher.scala:54) at com.qpercom.calendar.google.GoogleCalendarPusher.doCreate(GoogleCalendarPusher.scala:25) at com.qpercom.calendar.AbstractAPICalendarPusher.pushCreateOrUpdate(AbstractAPICalendarPus


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With some IDE there's a plugin to debug this kind of case. enter image description here

Anyway google-api-client 1.22.0, as you can see, depends on guava-jdk5 17. That version is in conflict with google-out-library.oath2-http that need version of guava > 20

Try to modify your pom.xml like this

    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.22.0</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava-jdk5</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

That produce this:

enter image description here

With this, you're excluding the old version and use version 23.0, instead of 17.0. I hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...