从FIRESTORE DB中删除文档使用JAR失败

时间:2018-04-27 12:00:46

标签: java firebase google-cloud-firestore

我正在处理一个非常奇怪的问题。

我在IntelliJ上开发了一个代码,它试图从FireStore DB中删除文档。

当我在IntelliJ中运行main()时,没有问题。

但是当我创建这个项目的JAR并将此jar作为“java -jar xxxxx.jar”运行时,我收到以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
        at com.google.api.gax.retrying.BasicRetryingFuture.<init>(BasicRetryingFuture.java:77)
        at com.google.api.gax.retrying.CallbackChainRetryingFuture.<init>(CallbackChainRetryingFuture.java:62)
        at com.google.api.gax.retrying.ScheduledRetryingExecutor.createFuture(ScheduledRetryingExecutor.java:84)
        at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:61)
        at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
        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:327)
        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.delete(DocumentReference.java:335)
        at main.main(main.java:26)

我在项目中使用Gradle,使用以下版本:

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.google.firebase:firebase-admin:5.10.0'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

我正在编写用于删除文档的代码:

FileInputStream serviceAccount = new FileInputStream("./ServiceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount)).build();
FirebaseApp.initializeApp(options);
Firestore db ;
CollectionReference to_be_Deleted ;



db = FirestoreClient.getFirestore();
ApiFuture<WriteResult> writeResult = db.collection("XXXXXX").document("WW4ovZ5amD56pxjd5NwY").delete();
System.out.println("Update time : " + writeResult.get().getUpdateTime());

我真的需要帮助解决这个问题。我希望有人能告诉我我的错误。

谢谢你们。

2 个答案:

答案 0 :(得分:0)

执行以下操作后,它现在对我有用。在IntelliJ中,我做了文件> 使缓存无效/重新启动。然后,我重建了 .jar 文件并成功运行。

当我第二次遇到此问题时,我还从头开始删除并重建了.jar。

答案 1 :(得分:-1)

我遇到了类似的问题,我通过从构建中排除guava-jdk5来解决它。

// Exclude guava-jdk5 from the dependencies in gradle.
// guava-jdk5 uses older versions of classes that do not contain all required methods, as a later version of guava is in the project, excluding will mean it is used instead.
    configurations {
      all*.exclude group: 'com.google.guava', module:'guava-jdk5'
    }