Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - Guava Dependency Breaking Jar Built With Kotlin

Issue

The Java/Kotlin application runs as expected in from the Main Class in IntelliJ's IDE. However, when the app is built into a .Jar file the following error occurs: java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.

This is an issue with refactoring the directory, module, root project, and/or group names.

Reproducing Error

I've moved the project to a new directory path and everything runs as expected. However, after I attempt to modify the directory, and/or module names and refactor the rootProject.name in settings.gradle and the group in the build.gradle is when the error above appears when running a new .jar build.

Full Error Message

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.GrpcDirectCallable.futureCall(GrpcDirectCallable.java:58)
at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:62)
at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
at com.google.cloud.firestore.FirestoreImpl.sendRequest(FirestoreImpl.java:330)
at com.google.cloud.firestore.UpdateBuilder.commit(UpdateBuilder.java:608)
at com.google.cloud.firestore.WriteBatch.commit(WriteBatch.java:41)
at com.google.cloud.firestore.DocumentReference.create(DocumentReference.java:141)
at com.google.cloud.firestore.CollectionReference.add(CollectionReference.java:115)
at com.google.cloud.firestore.CollectionReference.add(CollectionReference.java:141)
at PriceDifferenceTask.findMaxProfitAndPercentPriceDifference(PriceDifferenceTask.kt:167)
at PriceDifferenceTask.access$findMaxProfitAndPercentPriceDifference(PriceDifferenceTask.kt:15)
at PriceDifferenceTask$run$1.call(PriceDifferenceTask.kt:64)
at PriceDifferenceTask$run$1.call(PriceDifferenceTask.kt:15)
at rx.functions.Functions$6.call(Functions.java:169)
at rx.internal.operators.OperatorZip$Zip.tick(OperatorZip.java:252)
at rx.internal.operators.OperatorZip$Zip$InnerSubscriber.onNext(OperatorZip.java:323)
at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)
at rx.Observable.unsafeSubscribe(Observable.java:10256)
at rx.internal.operators.OperatorZip$Zip.start(OperatorZip.java:202)
at rx.internal.operators.OperatorZip$ZipSubscriber.onNext(OperatorZip.java:143)
at rx.internal.operators.OperatorZip$ZipSubscriber.onNext(OperatorZip.java:109)
at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)
at rx.Subscriber.setProducer(Subscriber.java:209)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10352)
at rx.Observable.subscribe(Observable.java:10319)
at rx.Observable.subscribe(Observable.java:10159)
at PriceDifferenceTask.run(PriceDifferenceTask.kt:66)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

Implementation

build.gradle

group 'coinverse'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.2.71'
    ext.junitJupiterVersion  = '5.0.3'

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

apply plugin: 'java'
apply plugin: 'kotlin'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    testImplementation 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.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
    implementation 'com.google.firebase:firebase-admin:6.5.0'
}

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

Gradle Dependency Tree

Attempted Solutions

  1. After examining similar issues on StackOverflow this appears to be related to a conflict with Google's Guava library. From the Gradle Dependencies above some libraries were calling older versions of Guava. All libraries in the build.gradle have been updated to their latest versions.
  2. Rebuilding project.
  3. IntelliJ Invalidate Cache and Restart
  4. Implementing current version of Guava in build.gradle: api "com.google.guava:guava:27.0-jre"
  5. Implementing lowest version of Guava in build.gradle found in dependency tree: implementation 'com.google.guava:guava:19.0'
  6. Implementing highest version of Guava in build.gradle found in dependency tree: implementation 'com.google.guava:guava:20.0'
  7. Attempting to exclude lowest version of Guava in build.gradle found in dependency tree: configurations {all*.exclude 'com.google.guava:guava:19.0'}
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

add the current version 27.0:

dependencies {
    api "com.google.guava:guava:27.0-jre"
}

and exclude both other versions 19.0 and 20.0, wherever they may be referenced.

./gradlew app:dependencies > dependencies.txt

or check with:

./gradlew app:dependencies | grep guava

for example (the firebase-admin is certainly a candidate):

// https://mvnrepository.com/artifact/com.google.firebase/firebase-admin
implementation ("com.google.firebase:firebase-admin:6.5.0") {
    exclude group: "com.google.guava", module: "guava"
}

there may be further references present.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...