7

I have an application I deploy on appengine using java8.
Lately when I tried deploying I get this error on run time:

Uncaught exception from servlet
java.lang.NoSuchMethodError: com.google.api.client.http.HttpTransport.isMtls()Z
    at com.google.api.services.storage.Storage$Builder.chooseEndpoint(Storage.java:11151)
    at com.google.api.services.storage.Storage$Builder.<init>(Storage.java:11184)
    at com.google.cloud.storage.spi.DefaultStorageRpc.<init>(DefaultStorageRpc.java:105)
    at com.google.cloud.storage.StorageOptions$DefaultStorageRpcFactory.create(StorageOptions.java:49)
    at com.google.cloud.storage.StorageOptions$DefaultStorageRpcFactory.create(StorageOptions.java:43)
    at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:482)
    at com.google.cloud.storage.StorageImpl.<init>(StorageImpl.java:93)
    at com.google.cloud.storage.StorageOptions$DefaultStorageFactory.create(StorageOptions.java:39)
    at com.google.cloud.storage.StorageOptions$DefaultStorageFactory.create(StorageOptions.java:33)
    at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:469)

here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>
    <version>1.1-SNAPSHOT</version>

    <groupId>my.com.myapp</groupId>
    <artifactId>myapp</artifactId>

    <repositories>
        <repository>
            <id>local-maven-repo</id>
            <url>file:///${project.basedir}/local-maven-repo</url>
        </repository>
    </repositories>
    <!-- [START set_versions] -->
    <properties>
        <appengine.sdk.version>1.9.46</appengine.sdk.version>
        <google-api-client.version>1.21.0</google-api-client.version>

        <objectify.version>5.1.5</objectify.version>
        <guava.version>18.0</guava.version>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <prerequisites>
        <maven>3.1.0</maven>
    </prerequisites>

    <dependencies>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>${appengine.sdk.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <type>jar</type>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine.tools</groupId>
            <artifactId>appengine-gcs-client</artifactId>
            <version>RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.apis/google-api-services-storage -->
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-storage</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-pubsub</artifactId>
            <version>RELEASE</version>
        </dependency>


        <!-- slf4j API frontend binding with JUL backend -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.7</version>
        </dependency>


        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-pubsub</artifactId>
            <version>0.8.3-alpha</version>
        </dependency>

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-bigquery</artifactId>
            <version>0.8.3-beta</version>
        </dependency>

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

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
        </dependency>
        <!-- for comparing jsons check if soppurted on appengine for tests only-->
        <dependency>
            <groupId>org.skyscreamer</groupId>
            <artifactId>jsonassert</artifactId>
            <version>1.4.0</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core for the integration reading from WEB-INF-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>2.5.6</version>
            <!--        <scope>integration</scope> -->
        </dependency>

        <!--added for pdf...-->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging-api -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging-api</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging-adapters -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging-adapters</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>fontbox</artifactId>
            <version>1.8.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>1.8.0-SNAPSHOT</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/fluent-hc -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>fluent-hc</artifactId>
            <version>4.5.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.3</version>
        </dependency>

        <dependency>
            <groupId>com.github.wnameless</groupId>
            <artifactId>json-flattener-java7</artifactId>
            <version>0.4.0</version>
        </dependency>


    </dependencies>

    <build>
        <!-- for hot reload of the web application -->
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        <plugins>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <projectId>my-project-id</projectId>
                    <version>my-version</version>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.7.v20160115</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>3.3</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!--integration-test-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>10</threadCount>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>


    </build>
</project>

I'll note that deploy works well when deploying on pc that has done deploy in the past, but whe deploying first time on new pc I get above error on run time

I assume I need to change the version on

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-storage</artifactId>
    <version>RELEASE</version>
</dependency>

what version should it be?

dina
  • 4,039
  • 6
  • 39
  • 67

5 Answers5

8

In general, such exception happens when you have two versions of the same class in the classpath. Some of the reasons that may happen are:

  1. Your dependencies include two version of google-api-client. I don't see any direct dependency so It could be a transitive dependency. You can run mvn dependency:tree and look for google-api-client dependencies and exclude one of the jars
  2. You are packing a provided dependency. It could be that app engine already include such jar with HttpTransport, if you also include this HttpTransport class into your artefact it will create problems. To fix this identify which dependency contains HttpTransport class and in your pom.xml add provided to it
  3. This class is included in the classpath from some old jar in some generated repository. If this is the case all you have to do is reset your environment. Clone the repository again and re-init app engine
Samuel Negri
  • 479
  • 4
  • 15
7

In my case, I updated to

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-bigquery</artifactId>
    <version>1.127.10</version>
</dependency>

which seems to have too old transitive dependencies for google-http-client and google-api-client, so I added those and had it fixed:

<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client</artifactId>
    <version>1.39.1</version>
</dependency>
<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.31.2</version>
</dependency>
exic
  • 2,220
  • 1
  • 22
  • 29
0

using RELEASE uses google-api-services-storage-v1-rev20201112-1.31.0.jar which has the above issue

I updated the dependency in pom.xml to the following,

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-storage</artifactId>
    <version>v1-rev20190129-1.26.0</version>
</dependency>

then ran

 mvn clean package

and now deploy is ok

dina
  • 4,039
  • 6
  • 39
  • 67
  • Downdating the version is not a very good solution. – Mr-K10 Mar 08 '21 at 06:50
  • In my case this is the right solution - since it's a program that was written years ago, and the RELEASE version was then `v1-rev20190129-1.26.0` - and newer versions are not compatible for the program – dina Mar 16 '21 at 07:51
0

rebuild with ./gradlew command and restart.

sangeun jo
  • 37
  • 9
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 21 '22 at 09:07
0

In addition to what @Samuel's answer adding the below dependency has worked for me.

compile ('com.google.cloud:google-cloud-storage:1.17.0')

Reference: https://www.baeldung.com/java-google-cloud-storage

Ravi Jain
  • 110
  • 7