用Kotlin制成的番石榴依赖性打破罐

时间:2018-10-18 19:58:54

标签: java gradle build.gradle guava android-guava

问题

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

这是重构目录,模块,根项目和/或组名的问题。

再现错误

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

完整错误消息

group

实施

build.gradle

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)

Gradle Dependency Tree

尝试的解决方案

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

2 个答案:

答案 0 :(得分:2)

添加当前版本27.0

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

exclude以及其他版本19.020.0,无论它们在何处被引用。

./gradlew app:dependencies > dependencies.txt

或通过以下方式检查:

./gradlew app:dependencies | grep guava

例如(firebase-admin当然是候选人):

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

可能还会有其他参考文献。

答案 1 :(得分:0)

解决方案

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

更新为依赖项

  1. compile更改为implementation
  2. 通过在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"
}