1

Problem

In trying this quickstart example, and of course, refactoring it to my needs/coding style, I am facing this weird Error:

Test Cases/Unit Tests/SMDEmailUtils FAILED.
Reason:
java.lang.NoSuchMethodError: com.google.api.client.http.HttpTransport.isMtls()Z
    at com.google.api.services.gmail.Gmail$Builder.chooseEndpoint(Gmail.java:11179)
    at com.google.api.services.gmail.Gmail$Builder.<init>(Gmail.java:11212)
    at com.signaturemd.utils.SMDGmailUtils.GetService(SMDGmailUtils.groovy:75)
    at com.signaturemd.utils.SMDGmailUtils.GetLastMessageHistoryID(SMDGmailUtils.groovy:89)
    at com.signaturemd.utils.SMDGmailUtils$GetLastMessageHistoryID.call(Unknown Source)
    at SMDEmailUtils.run(SMDEmailUtils:4)
    at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
//...

What did you try?

I try to research this Error message and it looks like my dependencies are all jacked up...

....so I close and clean up the workspace....

....close Katalon Studio, delete the .cache folder....

....run gradle clean build on the workspace folder....

....open back up Katalon Studio, find the test, run it again....

....and still face the same Error!

What's your build.gradle look like?

Like this:

plugins {
  id 'java'
  id "com.katalon.gradle-plugin" version "0.1.1"
}

repositories {
  mavenCentral()
}

dependencies {
  
  implementation 'com.github.javafaker:javafaker:1.0.2'

  implementation 'com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0'
}

OK, now what does your SMDGmailUtils class look like?

Nothin much...just the following:

package com.signaturemd.utils

import com.google.api.client.auth.oauth2.Credential
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.JsonFactory
import com.google.api.client.json.gson.GsonFactory
import com.google.api.client.util.store.FileDataStoreFactory
import com.google.api.services.gmail.Gmail
import com.google.api.services.gmail.GmailScopes
import com.google.api.services.gmail.model.History
import com.google.api.services.gmail.model.ListHistoryResponse

public class SMDGmailUtils {
    private static Gmail GmailServiceInstance;

    /**
     * Application name.
     */
    private static final String AppName = "Gmail Message Accessor";
    /**
     * Global instance of the JSON factory.
     */
    private static final JsonFactory JSONFactory = GsonFactory.getDefaultInstance();
    /**
     * Directory to store authorization tokens for this application.
     */
    private static final String TokensDirectoryPath = "tokens";

    /**
     * Global instance of the scopes required by this quickstart.
     * If modifying these scopes, delete your previously saved tokens/ folder.
     */
    private static final List<String> Scopes = [GmailScopes.GMAIL_ADDONS_CURRENT_MESSAGE_READONLY,];
    private static final String CredentialsFilePath = "./gmail-access-credentials.json";

    /**
     * Creates an authorized Credential object.
     *
     * @param httpTransport The network HTTP Transport.
     * @return An authorized Credential object.
     * @throws IOException If the credentials.json file cannot be found.
     */
    private static Credential getCredentials(final NetHttpTransport httpTransport)
    throws IOException {
        // Load client secrets.
        InputStream is = this.getResourceAsStream(this.CredentialsFilePath);
        if (is == null) {
            throw new FileNotFoundException("Resource not found: " + this.CredentialsFilePath);
        }

        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                httpTransport,
                this.JSONFactory,
                GoogleClientSecrets.load(this.JSONFactory, new InputStreamReader(is)),
                this.Scopes,
                )
                .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(this.TokensDirectoryPath)))
                .setAccessType("offline")
                .build();
        LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
        return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
    }

    private static Gmail GetService() {
        if (this.GmailServiceInstance == null) {
            final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
            this.GmailServiceInstance = new Gmail.Builder(httpTransport,
                    this.JSONFactory,
                    this.getCredentials(httpTransport),
                    )
                    .setApplicationName(this.AppName)
                    .build();
        }

        return this.GmailServiceInstance;
    }

    public static String GetNewMessage() {
        throw new cucumber.api.PendingException()
    }

    public static int GetLastMessageHistoryID() {
        ListHistoryResponse response = this.GetService()
                .users()
                .history()
                .list(SMDEmailUtils.GetMainEmail())
                .execute()

        return response.getHistory()
                .max({ History historyModel -> historyModel.getId() })
                .getId();
    }
}

The Error seems to be coming from right around the Gmail.Builder stuff...

What did you end up doing to generate your credentials JSON file?

I created OAuth client credentials with consent screen with the following Scopes:

.../auth/userinfo.email
.../auth/gmail.readonly

What do I need to do to resolve this Gmail.Builder Error?

UPDATE: I ran gradle dependencies and these were the resulting dependency trees:

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :dependencies

------------------------------------------------------------
Root project 'Zoho Katalon Project'
------------------------------------------------------------

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies

apiElements - API elements for main. (n)
No dependencies

archives - Configuration for archive artifacts. (n)
No dependencies

compileClasspath - Compile classpath for source set 'main'.
+--- com.github.javafaker:javafaker:1.0.2
|    +--- org.apache.commons:commons-lang3:3.5
|    +--- org.yaml:snakeyaml:1.23
|    \--- com.github.mifmif:generex:1.0.2
|         \--- dk.brics.automaton:automaton:1.11-8
+--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0
|    \--- com.google.api-client:google-api-client:2.0.0
|         +--- com.google.oauth-client:google-oauth-client:1.34.1
|         |    +--- com.google.http-client:google-http-client:1.42.0 -> 1.42.1
|         |    |    +--- org.apache.httpcomponents:httpclient:4.5.13
|         |    |    |    +--- org.apache.httpcomponents:httpcore:4.4.13 -> 4.4.15
|         |    |    |    +--- commons-logging:commons-logging:1.2
|         |    |    |    \--- commons-codec:commons-codec:1.11
|         |    |    +--- org.apache.httpcomponents:httpcore:4.4.15
|         |    |    +--- com.google.code.findbugs:jsr305:3.0.2
|         |    |    +--- com.google.guava:guava:30.1.1-android -> 31.1-jre
|         |    |    |    +--- com.google.guava:failureaccess:1.0.1
|         |    |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|         |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
|         |    |    |    +--- org.checkerframework:checker-qual:3.12.0
|         |    |    |    +--- com.google.errorprone:error_prone_annotations:2.11.0
|         |    |    |    \--- com.google.j2objc:j2objc-annotations:1.3
|         |    |    +--- com.google.j2objc:j2objc-annotations:1.3
|         |    |    +--- io.opencensus:opencensus-api:0.31.1
|         |    |    |    \--- io.grpc:grpc-context:1.27.2
|         |    |    \--- io.opencensus:opencensus-contrib-http-util:0.31.1
|         |    |         +--- io.opencensus:opencensus-api:0.31.1 (*)
|         |    |         \--- com.google.guava:guava:29.0-android -> 31.1-jre (*)
|         |    +--- com.google.http-client:google-http-client-gson:1.42.0 -> 1.42.1
|         |    |    +--- com.google.http-client:google-http-client:1.42.1 (*)
|         |    |    \--- com.google.code.gson:gson:2.9.0
|         |    \--- com.google.guava:guava:31.1-android -> 31.1-jre (*)
|         +--- com.google.http-client:google-http-client-gson:1.42.1 (*)
|         +--- com.google.guava:guava:31.1-jre (*)
|         +--- com.google.http-client:google-http-client-apache-v2:1.42.1
|         |    +--- com.google.http-client:google-http-client:1.42.1 (*)
|         |    +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
|         |    \--- org.apache.httpcomponents:httpcore:4.4.15
|         +--- org.apache.httpcomponents:httpcore:4.4.15
|         +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
|         \--- com.google.http-client:google-http-client:1.42.1 (*)
\--- org.codehaus.groovy:groovy-all:2.4.7

compileOnly - Compile only dependencies for source set 'main'. (n)
No dependencies

default - Configuration for default artifacts. (n)
No dependencies

implementation - Implementation only dependencies for source set 'main'. (n)
+--- com.github.javafaker:javafaker:1.0.2 (n)
\--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0 (n)

runtimeClasspath - Runtime classpath of source set 'main'.
+--- com.github.javafaker:javafaker:1.0.2
|    +--- org.apache.commons:commons-lang3:3.5
|    +--- org.yaml:snakeyaml:1.23
|    \--- com.github.mifmif:generex:1.0.2
|         \--- dk.brics.automaton:automaton:1.11-8
\--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0
     \--- com.google.api-client:google-api-client:2.0.0
          +--- com.google.oauth-client:google-oauth-client:1.34.1
          |    +--- com.google.http-client:google-http-client:1.42.0 -> 1.42.1
          |    |    +--- org.apache.httpcomponents:httpclient:4.5.13
          |    |    |    +--- org.apache.httpcomponents:httpcore:4.4.13 -> 4.4.15
          |    |    |    +--- commons-logging:commons-logging:1.2
          |    |    |    \--- commons-codec:commons-codec:1.11
          |    |    +--- org.apache.httpcomponents:httpcore:4.4.15
          |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    +--- com.google.guava:guava:30.1.1-android -> 31.1-jre
          |    |    |    +--- com.google.guava:failureaccess:1.0.1
          |    |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
          |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    |    +--- org.checkerframework:checker-qual:3.12.0
          |    |    |    +--- com.google.errorprone:error_prone_annotations:2.11.0
          |    |    |    \--- com.google.j2objc:j2objc-annotations:1.3
          |    |    +--- com.google.j2objc:j2objc-annotations:1.3
          |    |    +--- io.opencensus:opencensus-api:0.31.1
          |    |    |    \--- io.grpc:grpc-context:1.27.2
          |    |    \--- io.opencensus:opencensus-contrib-http-util:0.31.1
          |    |         +--- io.opencensus:opencensus-api:0.31.1 (*)
          |    |         \--- com.google.guava:guava:29.0-android -> 31.1-jre (*)
          |    +--- com.google.http-client:google-http-client-gson:1.42.0 -> 1.42.1
          |    |    +--- com.google.http-client:google-http-client:1.42.1 (*)
          |    |    \--- com.google.code.gson:gson:2.9.0
          |    \--- com.google.guava:guava:31.1-android -> 31.1-jre (*)
          +--- com.google.http-client:google-http-client-gson:1.42.1 (*)
          +--- com.google.guava:guava:31.1-jre (*)
          +--- com.google.http-client:google-http-client-apache-v2:1.42.1
          |    +--- com.google.http-client:google-http-client:1.42.1 (*)
          |    +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
          |    \--- org.apache.httpcomponents:httpcore:4.4.15
          +--- org.apache.httpcomponents:httpcore:4.4.15
          +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
          \--- com.google.http-client:google-http-client:1.42.1 (*)

runtimeElements - Elements of runtime for main. (n)
No dependencies

runtimeOnly - Runtime only dependencies for source set 'main'. (n)
No dependencies

shadow
\--- org.codehaus.groovy:groovy-all:2.4.7

shadowRuntimeElements (n)
No dependencies

testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies

testCompileClasspath - Compile classpath for source set 'test'.
+--- com.github.javafaker:javafaker:1.0.2
|    +--- org.apache.commons:commons-lang3:3.5
|    +--- org.yaml:snakeyaml:1.23
|    \--- com.github.mifmif:generex:1.0.2
|         \--- dk.brics.automaton:automaton:1.11-8
\--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0
     \--- com.google.api-client:google-api-client:2.0.0
          +--- com.google.oauth-client:google-oauth-client:1.34.1
          |    +--- com.google.http-client:google-http-client:1.42.0 -> 1.42.1
          |    |    +--- org.apache.httpcomponents:httpclient:4.5.13
          |    |    |    +--- org.apache.httpcomponents:httpcore:4.4.13 -> 4.4.15
          |    |    |    +--- commons-logging:commons-logging:1.2
          |    |    |    \--- commons-codec:commons-codec:1.11
          |    |    +--- org.apache.httpcomponents:httpcore:4.4.15
          |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    +--- com.google.guava:guava:30.1.1-android -> 31.1-jre
          |    |    |    +--- com.google.guava:failureaccess:1.0.1
          |    |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
          |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    |    +--- org.checkerframework:checker-qual:3.12.0
          |    |    |    +--- com.google.errorprone:error_prone_annotations:2.11.0
          |    |    |    \--- com.google.j2objc:j2objc-annotations:1.3
          |    |    +--- com.google.j2objc:j2objc-annotations:1.3
          |    |    +--- io.opencensus:opencensus-api:0.31.1
          |    |    |    \--- io.grpc:grpc-context:1.27.2
          |    |    \--- io.opencensus:opencensus-contrib-http-util:0.31.1
          |    |         +--- io.opencensus:opencensus-api:0.31.1 (*)
          |    |         \--- com.google.guava:guava:29.0-android -> 31.1-jre (*)
          |    +--- com.google.http-client:google-http-client-gson:1.42.0 -> 1.42.1
          |    |    +--- com.google.http-client:google-http-client:1.42.1 (*)
          |    |    \--- com.google.code.gson:gson:2.9.0
          |    \--- com.google.guava:guava:31.1-android -> 31.1-jre (*)
          +--- com.google.http-client:google-http-client-gson:1.42.1 (*)
          +--- com.google.guava:guava:31.1-jre (*)
          +--- com.google.http-client:google-http-client-apache-v2:1.42.1
          |    +--- com.google.http-client:google-http-client:1.42.1 (*)
          |    +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
          |    \--- org.apache.httpcomponents:httpcore:4.4.15
          +--- org.apache.httpcomponents:httpcore:4.4.15
          +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
          \--- com.google.http-client:google-http-client:1.42.1 (*)

testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies

testImplementation - Implementation only dependencies for source set 'test'. (n)
No dependencies

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- com.github.javafaker:javafaker:1.0.2
|    +--- org.apache.commons:commons-lang3:3.5
|    +--- org.yaml:snakeyaml:1.23
|    \--- com.github.mifmif:generex:1.0.2
|         \--- dk.brics.automaton:automaton:1.11-8
\--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0
     \--- com.google.api-client:google-api-client:2.0.0
          +--- com.google.oauth-client:google-oauth-client:1.34.1
          |    +--- com.google.http-client:google-http-client:1.42.0 -> 1.42.1
          |    |    +--- org.apache.httpcomponents:httpclient:4.5.13
          |    |    |    +--- org.apache.httpcomponents:httpcore:4.4.13 -> 4.4.15
          |    |    |    +--- commons-logging:commons-logging:1.2
          |    |    |    \--- commons-codec:commons-codec:1.11
          |    |    +--- org.apache.httpcomponents:httpcore:4.4.15
          |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    +--- com.google.guava:guava:30.1.1-android -> 31.1-jre
          |    |    |    +--- com.google.guava:failureaccess:1.0.1
          |    |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
          |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    |    +--- org.checkerframework:checker-qual:3.12.0
          |    |    |    +--- com.google.errorprone:error_prone_annotations:2.11.0
          |    |    |    \--- com.google.j2objc:j2objc-annotations:1.3
          |    |    +--- com.google.j2objc:j2objc-annotations:1.3
          |    |    +--- io.opencensus:opencensus-api:0.31.1
          |    |    |    \--- io.grpc:grpc-context:1.27.2
          |    |    \--- io.opencensus:opencensus-contrib-http-util:0.31.1
          |    |         +--- io.opencensus:opencensus-api:0.31.1 (*)
          |    |         \--- com.google.guava:guava:29.0-android -> 31.1-jre (*)
          |    +--- com.google.http-client:google-http-client-gson:1.42.0 -> 1.42.1
          |    |    +--- com.google.http-client:google-http-client:1.42.1 (*)
          |    |    \--- com.google.code.gson:gson:2.9.0
          |    \--- com.google.guava:guava:31.1-android -> 31.1-jre (*)
          +--- com.google.http-client:google-http-client-gson:1.42.1 (*)
          +--- com.google.guava:guava:31.1-jre (*)
          +--- com.google.http-client:google-http-client-apache-v2:1.42.1
          |    +--- com.google.http-client:google-http-client:1.42.1 (*)
          |    +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
          |    \--- org.apache.httpcomponents:httpcore:4.4.15
          +--- org.apache.httpcomponents:httpcore:4.4.15
          +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
          \--- com.google.http-client:google-http-client:1.42.1 (*)

testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies

(*) - dependencies omitted (listed previously)

(n) - Not resolved (configuration is not meant to be resolved)

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 3m 39s
2 actionable tasks: 2 executed

Error still happens even if I use SCREAMING_SNAKE_CASE on all the static fields!!

Mike Warren
  • 3,796
  • 5
  • 47
  • 99
  • I think I have a working sample with Maven. Not sure i have tried gradle before. Would this help? – Linda Lawton - DaImTo Oct 02 '22 at 18:59
  • I'm now convinced that Katalon Studio itself may be causing this... I've tried everything and it's still not working... Yea, let's see that Maven solution, and maybe we can research how to translate it to Gradle... For the record, I'm not sure why I'm getting this Error (despite Katalon Studio itself causing it), and why this question has only downvotes and no activity?? – Mike Warren Oct 03 '22 at 02:22
  • similar question: https://stackoverflow.com/questions/65826798/java-lang-nosuchmethoderror-com-google-api-client-http-httptransport-ismtlsz – daggett Oct 03 '22 at 07:49
  • Yea, I linked that question. Nothing I was trying on there was working. Last night, I found out that the environment of Katalon Studio may be the problem. – Mike Warren Oct 03 '22 at 13:13
  • 1
    Have you tried the `gradle katalonCopyDependencies` task with closed Katalon Studio? The plugin manual mentions this. – andi Oct 06 '22 at 19:35
  • It didn't work :'( I raised a ticket on Katalon Studio forum. Doubt they'll end up doing anything about it tho.... https://forum.katalon.com/t/weird-java-lang-nosuchmethoderror-that-pops-up-when-trying-to-use-gmail-api-with-katalon-studio/79172 – Mike Warren Oct 07 '22 at 03:17

0 Answers0