从Java连接到Firebase时的java.lang.NoSuchMethodError

时间:2018-01-12 09:37:11

标签: java maven firebase firebase-admin

我正在尝试将我的Java Web项目连接到Firebase,因此我可以将我的数据存储在Firestore中。我正在使用Java Admin SDK,遵循官方指南:FirebaseAdminSDK。遗憾的是,我在初始化FirebaseAp时遇到异常:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:352)
at com.google.firebase.FirebaseApp.getOptions(FirebaseApp.java:267)
at com.google.firebase.FirebaseApp$TokenRefresher.<init>(FirebaseApp.java:434)
at com.google.firebase.FirebaseApp$TokenRefresher$Factory.create(FirebaseApp.java:535)
at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:113)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:201)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:188)

现在,我在这里和那里阅读,这是番石榴项目的问题,建议使用不同版本的番石榴库。我尝试了从18开始的所有版本。

然后,我读到它可能是由我的类路径中不同库引用的多个番石榴库引起的,在不同的版本中互相争斗。所以,我检查了maven依赖树,看看是否有多个依赖guava。不。

然后,我解压缩.WAR文件以查看使用我的应用程序将精确的罐子部署到glassfish。那里只有一个番石榴罐(我的pom.xml文件指向的那个)。 说实话,我已经没有想法了。请帮忙。您可以在下面看到pom.xml和生成的maven依赖关系树。

的pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.greenstudio</groupId>
    <artifactId>trekking-project</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>trekking-project</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>5.6.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>guava</artifactId>
                    <groupId>com.google.guava</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.9</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
            <version>2.5.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.3.3</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.3</version>
        </dependency>
        <dependency>
            <groupId>primefaces.blacktie</groupId>
            <artifactId>primefaces.blacktie</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>bootstrap</groupId>
            <artifactId>bootstrap</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons.validator.routines.EmailValidatororg.apache.commons.validator.routines.EmailValidator</groupId>
            <artifactId>org.apache.commons.validator.routines.EmailValidator</artifactId>
            <version>1.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

依赖树

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom (11 kB at 18 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.jar (153 kB at 709 kB/s)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building trekking-project 1.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for primefaces:primefaces:jar:5.3 is missing, no dependency information available
[WARNING] The POM for primefaces.blacktie:primefaces.blacktie:jar:1.0 is missing, no dependency information available
[WARNING] The POM for bootstrap:bootstrap:jar:1.0 is missing, no dependency information available
[WARNING] The POM for org.apache.commons.validator.routines.EmailValidatororg.apache.commons.validator.routines.EmailValidator:org.apache.commons.validator.routines.EmailValidator:jar:1.0 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ trekking-project ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.pom (3.4 kB at 38 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.pom (5.2 kB at 58 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.jar (27 kB at 105 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.jar (186 kB at 704 kB/s)
[INFO] com.greenstudio:trekking-project:war:1.0
[INFO] +- com.google.firebase:firebase-admin:jar:5.6.0:compile
[INFO] |  +- com.google.api-client:google-api-client:jar:1.22.0:compile
[INFO] |  |  +- com.google.oauth-client:google-oauth-client:jar:1.22.0:compile
[INFO] |  |  \- com.google.http-client:google-http-client-jackson2:jar:1.22.0:compile
[INFO] |  |     \- com.fasterxml.jackson.core:jackson-core:jar:2.1.3:compile
[INFO] |  +- com.google.api-client:google-api-client-gson:jar:1.22.0:compile
[INFO] |  |  \- com.google.http-client:google-http-client-gson:jar:1.22.0:compile
[INFO] |  |     \- com.google.code.gson:gson:jar:2.1:compile
[INFO] |  +- com.google.http-client:google-http-client:jar:1.22.0:compile
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.api:api-common:jar:1.2.0:compile
[INFO] |  +- com.google.auth:google-auth-library-oauth2-http:jar:0.8.0:compile
[INFO] |  |  \- com.google.auth:google-auth-library-credentials:jar:0.8.0:compile
[INFO] |  +- com.google.cloud:google-cloud-storage:jar:1.7.0:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core:jar:1.7.0:compile
[INFO] |  |  |  +- com.google.api:gax:jar:1.8.1:compile
[INFO] |  |  |  +- com.google.protobuf:protobuf-java-util:jar:3.3.1:compile
[INFO] |  |  |  +- com.google.api.grpc:proto-google-common-protos:jar:0.1.20:compile
[INFO] |  |  |  \- com.google.api.grpc:proto-google-iam-v1:jar:0.1.20:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core-http:jar:1.7.0:compile
[INFO] |  |  |  +- com.google.http-client:google-http-client-appengine:jar:1.22.0:compile
[INFO] |  |  |  \- com.google.http-client:google-http-client-jackson:jar:1.22.0:compile
[INFO] |  |  |     \- org.codehaus.jackson:jackson-core-asl:jar:1.9.11:compile
[INFO] |  |  \- com.google.apis:google-api-services-storage:jar:v1-rev108-1.22.0:compile
[INFO] |  +- com.google.cloud:google-cloud-firestore:jar:0.25.0-beta:compile
[INFO] |  |  +- io.netty:netty-tcnative-boringssl-static:jar:2.0.3.Final:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core-grpc:jar:1.7.0:compile
[INFO] |  |  |  +- com.google.protobuf:protobuf-java:jar:3.3.1:compile
[INFO] |  |  |  +- io.grpc:grpc-protobuf:jar:1.6.1:compile
[INFO] |  |  |  |  \- io.grpc:grpc-protobuf-lite:jar:1.6.1:compile
[INFO] |  |  |  \- io.grpc:grpc-context:jar:1.6.1:compile
[INFO] |  |  +- com.google.api:gax-grpc:jar:0.25.1:compile
[INFO] |  |  |  +- com.google.auto.value:auto-value:jar:1.2:compile
[INFO] |  |  |  \- org.threeten:threetenbp:jar:1.3.3:compile
[INFO] |  |  +- com.google.api.grpc:proto-google-cloud-firestore-v1beta1:jar:0.1.20:compile
[INFO] |  |  +- io.grpc:grpc-netty:jar:1.6.1:compile
[INFO] |  |  |  +- io.grpc:grpc-core:jar:1.6.1:compile (version selected from constraint [1.6.1,1.6.1])
[INFO] |  |  |  |  +- com.google.errorprone:error_prone_annotations:jar:2.0.19:compile
[INFO] |  |  |  |  +- com.google.instrumentation:instrumentation-api:jar:0.4.3:compile
[INFO] |  |  |  |  \- io.opencensus:opencensus-api:jar:0.5.1:compile
[INFO] |  |  |  +- io.netty:netty-codec-http2:jar:4.1.14.Final:compile (version selected from constraint [4.1.14.Final,4.1.14.Final])
[INFO] |  |  |  \- io.netty:netty-handler-proxy:jar:4.1.14.Final:compile
[INFO] |  |  |     \- io.netty:netty-codec-socks:jar:4.1.14.Final:compile
[INFO] |  |  +- io.grpc:grpc-stub:jar:1.6.1:compile
[INFO] |  |  \- io.grpc:grpc-auth:jar:1.6.1:compile
[INFO] |  +- org.json:json:jar:20160810:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- io.netty:netty-codec-http:jar:4.1.14.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.1.14.Final:compile
[INFO] |  +- io.netty:netty-handler:jar:4.1.14.Final:compile
[INFO] |  |  \- io.netty:netty-buffer:jar:4.1.14.Final:compile
[INFO] |  |     \- io.netty:netty-common:jar:4.1.14.Final:compile
[INFO] |  \- io.netty:netty-transport:jar:4.1.14.Final:compile
[INFO] |     \- io.netty:netty-resolver:jar:4.1.14.Final:compile
[INFO] +- com.google.guava:guava:jar:21.0:compile
[INFO] +- joda-time:joda-time:jar:2.9.9:compile
[INFO] +- org.eclipse.persistence:eclipselink:jar:2.5.2:provided
[INFO] |  +- org.eclipse.persistence:javax.persistence:jar:2.1.0:provided
[INFO] |  \- org.eclipse.persistence:commonj.sdo:jar:2.1.1:provided
[INFO] +- org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:jar:2.5.2:provided
[INFO] |  +- org.eclipse.persistence:org.eclipse.persistence.core:jar:2.5.2:provided
[INFO] |  |  \- org.eclipse.persistence:org.eclipse.persistence.asm:jar:2.5.2:provided
[INFO] |  \- org.eclipse.persistence:org.eclipse.persistence.jpa:jar:2.5.2:provided
[INFO] |     +- org.eclipse.persistence:org.eclipse.persistence.antlr:jar:2.5.2:provided
[INFO] |     \- org.eclipse.persistence:org.eclipse.persistence.jpa.jpql:jar:2.5.2:provided
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.3.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- primefaces:primefaces:jar:5.3:compile
[INFO] +- primefaces.blacktie:primefaces.blacktie:jar:1.0:compile
[INFO] +- bootstrap:bootstrap:jar:1.0:compile
[INFO] +- org.apache.commons.validator.routines.EmailValidatororg.apache.commons.validator.routines.EmailValidator:org.apache.commons.validator.routines.EmailValidator:jar:1.0:compile
[INFO] \- javax:javaee-web-api:jar:7.0:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.897 s
[INFO] Finished at: 2018-01-12T10:16:59+01:00
[INFO] Final Memory: 15M/215M
[INFO] ------------------------------------------------------------------------

我甚至下载了google firebase sdk的github存储库并删除了那里的所有guava代码引用,但是在尝试读取/写入Firestore时我遇到了类似的错误。似乎其他一些谷歌库依赖于那个糟糕的小罐子。

1 个答案:

答案 0 :(得分:1)

我在不同的依赖项中遇到了与Guava版本相同的问题。

我在Gradle中解决了这个问题:

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:guava:17.0'
    }
}

应该有Maven方式,否则从所有依赖项中排除Guava并使用您的版本明确添加它。

它在全球范围内强制执行Guava版本。幸运的是,版本17与我的所有依赖项兼容。无论是16岁还是18岁以上......这些都是使用番石榴的悲伤。

希望它有所帮助, 此致