用Kotlin制成的番石榴依赖性破碎罐 [英] Guava Dependency Breaking Jar Built With Kotlin

查看:98
本文介绍了用Kotlin制成的番石榴依赖性破碎罐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java/Kotlin应用程序可以按预期从IntelliJ IDE的Main Class中运行.但是,当应用程序内置到 .Jar 文件中时,会发生以下错误:java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.

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.

我已经将项目移到了新的目录路径,并且一切都按预期运行.但是,在尝试修改目录和/或模块名称并重构 settings.gradle 中的rootProject.name build.gradle 中的group之后,当运行新的 .jar 版本时出现上述错误.

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.

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)

实施

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

等级依赖树

尝试的解决方案

  1. 在检查StackOverflow上的类似问题之后,这似乎与与Google的Guava库发生冲突有关.从上面的Gradle依赖关系中,一些库正在调用旧版本的Guava. build.gradle 中的所有库都已更新为最新版本.
  2. 重建项目.
  3. IntelliJ使缓存无效并重新启动
  4. build.gradle 中实现番石榴的当前版本:api "com.google.guava:guava:27.0-jre"
  5. 在依赖项树中找到的 build.gradle 中实现最低版本的Guava:
  6. 在依赖项树中找到的 build.gradle 中实现番石榴的最高版本:implementation 'com.google.guava:guava:20.0'
  7. 尝试在依赖项树中找到的 build.gradle 中排除最低版本的Guava:configurations {all*.exclude 'com.google.guava:guava:19.0'}
  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'}

推荐答案

解决方案

Jar 构建在更新我的库依赖关系并重新拉出在与Github不同的机器上构建的版本后重新定义了项目级别的SDK后,再次开始工作.

Solution

The Jar build started working again after updating my library dependencies and redefining the Project level SDK when re-pulling a version built on a different machine from Github.

  1. compile更改为implementation.
  2. 通过在Google上搜索每个项目的最新版本来更新版本号.
  1. Changed compile to implementation.
  2. Updated version numbers by searching for each project's latest version on Google.

build.grade

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 "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'
    implementation 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
}

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

这篇关于用Kotlin制成的番石榴依赖性破碎罐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆