0

Issue

The Kotlin app runs as expected from the main method in IntelliJ's IDE. However, after setting up the project on a new machine the compiled Jar throws the following exception which is related to a Firestore library:

Error: Exception in thread "Timer-0" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

Full Error

Exception in thread "Timer-0" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
at io.grpc.internal.ClientCallImpl.<init>(ClientCallImpl.java:96)
at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:662)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor.interceptCall(CensusTracingModule.java:382)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor.interceptCall(CensusStatsModule.java:675)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at com.google.api.gax.grpc.GrpcHeaderInterceptor.interceptCall(GrpcHeaderInterceptor.java:81)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at com.google.api.gax.grpc.GrpcMetadataHandlerInterceptor.interceptCall(GrpcMetadataHandlerInterceptor.java:55)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:636)
at com.google.api.gax.grpc.GrpcClientCalls.newCall(GrpcClientCalls.java:66)
at com.google.api.gax.grpc.GrpcDirectServerStreamingCallable.call(GrpcDirectServerStreamingCallable.java:65)
at com.google.api.gax.grpc.GrpcExceptionServerStreamingCallable.call(GrpcExceptionServerStreamingCallable.java:62)
at com.google.api.gax.rpc.WatchdogServerStreamingCallable.call(WatchdogServerStreamingCallable.java:69)
at com.google.api.gax.rpc.ServerStreamingCallable$1.call(ServerStreamingCallable.java:220)
at com.google.api.gax.rpc.ServerStreamingCallable$1.call(ServerStreamingCallable.java:220)
at com.google.api.gax.rpc.ServerStreamingCallable.serverStreamingCall(ServerStreamingCallable.java:166)
at com.google.api.gax.rpc.ServerStreamingCallable.serverStreamingCall(ServerStreamingCallable.java:178)
at com.google.cloud.firestore.FirestoreImpl.streamRequest(FirestoreImpl.java:339)
at com.google.cloud.firestore.Query.stream(Query.java:955)
at com.google.cloud.firestore.Query.get(Query.java:995)
at com.google.cloud.firestore.Query.get(Query.java:965)
at content.Task.getQueryParams(ContentTasks.kt:69)
at content.Task.run(ContentTasks.kt:54)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)

Setup

build.gradle dependencies

compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
// JUnit Jupiter API and TestEngine implementation
testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testCompile("org.assertj:assertj-core:3.10.0")
// To avoid compiler warnings about @API annotations in JUnit code
testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
implementation 'com.google.firebase:firebase-admin:6.3.0'
implementation 'com.google.apis:google-api-services-youtu be:v3-rev204-1.23.0'

MANIFEST.MF

Manifest-Version: 1.0
Main-Class: Initialization

Attempted Solutions

  1. Rebuilding Jar Artifact.
  2. Rebuilding project.
  3. Invalidating IntelliJ cache and restarting IDE.
  4. Re-syncing Gradle file.
  5. Restarting computer
  6. Updated gradle libraries, excluded guava where older versions were used, and explicitly define guava and com.google.api libraries.

buildscript {
    ext.kotlin_version = '1.3.10'
    ext.junitJupiterVersion  = '5.3.2'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
    }
}

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}

version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "com.google.guava:guava:27.0.1-jre"
    implementation ('com.google.api:gax:1.33.1') {
        exclude group: "com.google.guava", module: "guava"
    }
    implementation ('com.google.api:gax-grpc:1.33.1') {
        exclude group: "com.google.guava", module: "guava"
    }
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testImplementation group: 'junit', name: 'junit', version: '5.3.2'
    // JUnit Jupiter API and TestEngine implementation
    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
    testImplementation("org.assertj:assertj-core:3.11.1")
    // To avoid compiler warnings about @API annotations in JUnit code
    testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
    implementation ('com.google.firebase:firebase-admin:6.6.0') {
        exclude group: "com.google.guava", module: "guava"
    }
    implementation ('com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'){
        exclude group: "com.google.guava", module: "guava"
    }
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

Guava dependencies with attempted solution #6: gradle dependencyInsight --dependency com.google.guava

com.google.guava:failureaccess:1.0.1
    variant "runtime" [
      org.gradle.status                  = release (not requested)
  Requested attributes not found in the selected variant:
     org.gradle.usage                   = java-api
     org.jetbrains.kotlin.platform.type = jvm
   ]

com.google.guava:failureaccess:1.0.1
\--- com.google.guava:guava:27.0.1-jre
     \--- compileClasspath

com.google.guava:guava:27.0.1-jre
   variant "default" [
  org.gradle.status                  = release (not requested)
  Requested attributes not found in the selected variant:
     org.gradle.usage                   = java-api
     org.jetbrains.kotlin.platform.type = jvm
   ]

com.google.guava:guava:27.0.1-jre
\--- compileClasspath

com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
   variant "runtime" [
  org.gradle.status                  = release (not requested)
  Requested attributes not found in the selected variant:
     org.gradle.usage                   = java-api
     org.jetbrains.kotlin.platform.type = jvm
   ]

com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
\--- com.google.guava:guava:27.0.1-jre
     \--- compileClasspath

Guava Versions Being Used: find ~/.gradle -name 'guava*.jar'

Adams-MacBook-Pro:coinverse-media adamhurwitz$ find ~/.gradle -name 'guava*.jar'
/Users/adamhurwitz/.gradle/caches/jars-3/e78d086d43fe590d24040393ce6cb069/guava-21.0.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/20.0/89507701249388e1ed5ddcf8c41f4ce1be7831ef/guava-20.0.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/20.0/9c8493c7991464839b612d7547d6c263adf08f75/guava-20.0-sources.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/23.0/c947004bb13d18182be60077ade044099e4f26f1/guava-23.0.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/23.0/ed233607c5c11e1a13a3fd760033ed5d9fe525c2/guava-23.0-sources.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/23.6-android/13f7bbf4f1b95dbec11df43200bfdb913ccd4072/guava-23.6-android.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/23.6-android/92dee3d8391d9d45d8c6323bc350b606aac89a12/guava-23.6-android-sources.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0-jre/c6ad87d2575af8ac8ec38e28e75aefa882cc3a1f/guava-27.0-jre.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0-jre/d6484e2ee11ad928ccf61cf3e4ce9cedc2eead7e/guava-27.0-jre-sources.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-jre/bd41a290787b5301e63929676d792c507bbc00ae/guava-27.0.1-jre.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-jre/cb5c1119df8d41a428013289b193eba3ccaf5f60/guava-27.0.1-jre-sources.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava-jdk5/17.0/463f8378feba44df7ba7cd9272d01837dad62b36/guava-jdk5-17.0.jar
/Users/adamhurwitz/.gradle/caches/modules-2/files-2.1/com.google.guava/guava-jdk5/17.0/cc6729ce0bc6cc29441cb3a04acad02aeeebb26e/guava-jdk5-17.0-sources.jar
/Users/adamhurwitz/.gradle/caches/transforms-1/files-1.1/guava-23.0.jar
/Users/adamhurwitz/.gradle/caches/transforms-1/files-1.1/guava-23.6-android.jar
/Users/adamhurwitz/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4/lib/guava-jdk5-17.0.jar
/Users/adamhurwitz/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/gradle-4.6/lib/guava-jdk5-17.0.jar
AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134
  • 1
    Did you try to check if there are any dependency conflicts? https://stackoverflow.com/q/21311727/1654233 can perhaps help. – yegodm Dec 01 '18 at 01:18
  • Thanks @yegodm! I created a dependency report: [scans.gradle.com/s/qmwmf3z55zdq6](https://scans.gradle.com/s/qmwmf3z55zdq6/). What strategy would you recommend for identifying which conflict(s) are causing the issue? – AdamHurwitz Dec 03 '18 at 00:09
  • 1
    The strategy is always the same - identify the library which causing the problem ( I guess it is Google guava), and figure out which version (19.0 vs 20.0) does not have the method reported by the exception. Then you'll have to find the way how to enforce the proper version in Gradle. – yegodm Dec 03 '18 at 00:24
  • I attempted to exclude **guava** from both the Firebase and YouTube libraries without success. `implementation ('com.google.firebase:firebase-admin:6.6.0') { exclude group: "com.google.guava", module: "guava" } implementation ('com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'){ exclude group: "com.google.guava", module: "guava" }` while implementing the latest **guava** version: `api "com.google.guava:guava:27.0.1-jre"` – AdamHurwitz Dec 03 '18 at 01:09
  • In the link in your previous question, there's ``guava:27.0-android`. You can't use `-android` and `-jre` at the same time. `+++` A different approach: Remove your `~/.gradle` directory and let gradle compile your project. With `find ~/.gradle -name 'guava*.jar'`, you'll see what Guava versions get used. – maaartinus Dec 03 '18 at 01:17
  • Looks like runtime classpath is very different. The method has been since 18.0, and you somehow endup with earlier version. – yegodm Dec 03 '18 at 01:18
  • @maaartinus, good call. I've adjusted to use `api "com.google.guava:guava:27.0.1-jre"`. – AdamHurwitz Dec 03 '18 at 01:25
  • @yegodm, May you please elaborate on the **classpath**? Which classpath is different from what? – AdamHurwitz Dec 03 '18 at 01:37
  • I'm not an Android expert, but I'd try something like this https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/ to dump actual runtime classpath to a log/console. – yegodm Dec 03 '18 at 01:53
  • @maaartinus - I've done as recommended removing the `gradle` dir and letting it re-compile. I've posted the results of the command `find ~/.gradle -name 'guava*.jar'` above under the attempted solutions section. It looks like some Android dependencies are being called which could be potentially an issue since this is purely a AppEngine Kotlin/Java Jar project. – AdamHurwitz Dec 03 '18 at 02:01
  • @yegodm, I believe @maaartinus' method of `find ~/.gradle -name 'guava*.jar'` produced the same result. I've posted the results under the *Attempted Solutions* section in my post above. It appears both Android and older versions of Guava are showing. Could that be the root of the issue? – AdamHurwitz Dec 03 '18 at 02:06
  • I was talking about actual classpath of running application. Anyway I'd suspect guava-jdk5-17.0.jar is the culprit. – yegodm Dec 03 '18 at 02:26
  • How can I resolve this @yegodm? When I do `gradle dependencies --scan` and search for `guava-jdk5-17.0.jar` in the output log it does not show under any of the libraries... Output log: [scans.gradle.com/s/fyqwsge3gvja2/console-log](https://scans.gradle.com/s/fyqwsge3gvja2/console-log) – AdamHurwitz Dec 03 '18 at 02:32
  • https://stackoverflow.com/a/36403041/1654233 ? – yegodm Dec 03 '18 at 02:39
  • I attempted to use `exclude group: "com.google.guava", module: "guava-jdk5")}` for Firebase and YouTube, but I am seeing the same issue. This seems like it should of worked since the error is coming from Firebase: `at com.google.cloud.firestore.FirestoreImpl.streamRequest(FirestoreImpl.java:339) at com.google.cloud.firestore.Query.stream(Query.java:955) at com.google.cloud.firestore.Query.get(Query.java:995) at com.google.cloud.firestore.Query.get(Query.java:965) at content.Task.getQueryParams(ContentTasks.kt:69) at content.Task.run(ContentTasks.kt:54)` – AdamHurwitz Dec 03 '18 at 03:21
  • What `module: "guava-jdk5"`? I don't know the exact syntax, but shouldn't it be `name` (just like in `compile`)? `+++` Does deleting the old dependency from `~/.gradle` help? `+++` It doesn't matter where the exception comes from, as the culprit is the part using the old version (assuming you prefer the new one). – maaartinus Dec 03 '18 at 23:05

1 Answers1

0

Have you tried updating your GAX-Java dependency past version 1.33.1? It looks like version 1.35.0 uses Guava 26.0.

netdpb
  • 401
  • 3
  • 4