Kotlin Jar错误:线程“ Timer-0”中的异常java.lang.NoSuchMethodError

时间:2018-12-01 01:12:56

标签: java intellij-idea kotlin jar google-cloud-firestore

问题

Kotlin应用程序可以按预期从IntelliJ IDE中的 main 方法运行。但是,在新计算机上设置项目后,编译的 Jar 会引发与 Firestore 库相关的以下异常:

错误: 线程“ Timer-0”中的异常java.lang.NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava / util / concurrent /执行者;

完全错误

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)

设置

build.gradle 依赖项

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

尝试的解决方案

  1. 重建Jar工件。
  2. 重建项目。
  3. 使IntelliJ缓存无效并重新启动IDE。
  4. 重新同步Gradle文件。
  5. 重新启动计算机
  6. 更新了gradle库,排除了使用旧版本的guava,并明确定义了 guava com.google.api 库。

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"
}

尝试使用解决方案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

正在使用的番石榴版本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

1 个答案:

答案 0 :(得分:0)

您是否尝试过更新1.33.1版之前的GAX-Java依赖关系?看起来1.35.0版使用了Guava 26.0。