0

我正在尝试将 Cloud Endpoints Framework v2 升级到 Java 8。我唯一改变的是:

sourceCompatibility = 1.8
targetCompatibility = 1.8

在 backend.gradle 里面。

现在,通过 Endpoints API 的每次调用都会引发以下错误:

java.lang.NoSuchMethodError: com.google.common.reflect.TypeToken.isSubtypeOf(Ljava/lang/reflect/Type;)Z
at com.google.api.server.spi.config.model.Types.getArrayItemType(Types.java:138)

这似乎暗示了 Guava 依赖问题,这很奇怪,因为我没有更改依赖关系。我尝试在 project.gradle 中使用 Guava 20.0 的类路径,但没有成功。

按照我的 Gradle 文件(Gradle 4.1):

后端.gradle

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
    }
}

repositories {
    mavenCentral();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    providedCompile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
    compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.60'
    compile 'com.google.endpoints:endpoints-framework:2.0.10'
    compile 'com.google.appengine.tools:appengine-gcs-client:0.7'
    compile 'jstl:jstl:1.2'
    compile 'javax.inject:javax.inject:1'
    compile 'com.googlecode.objectify:objectify:5.1.21'
    ...
}

appengine {  // App Engine tasks configuration
    deploy {   // deploy configuration
        project = findProperty("appengine.deploy.project")
        version = findProperty("appengine.deploy.version")
        def promoteProp = findProperty("appengine.deploy.promote")
        if (promoteProp != null) {
            promote = new Boolean(promoteProp)
        }
    }
}

项目.gradle

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
        classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2018-01-03 更新

输出gradle dependencyInsight --dependency guava

com.google.guava:guava:20.0 (conflict resolution)
\--- com.googlecode.objectify:objectify:5.1.21
     \--- compileClasspath

com.google.guava:guava:18.0 -> 20.0
+--- com.optimaize.languagedetector:language-detector:0.6
|    \--- compileClasspath
\--- io.swagger:swagger-core:1.5.9
     \--- com.google.endpoints:endpoints-framework:2.0.10
          \--- compileClasspath

com.google.guava:guava:19.0 -> 20.0
+--- com.google.appengine.tools:appengine-gcs-client:0.7
|    \--- compileClasspath
\--- com.google.endpoints:endpoints-framework:2.0.10
     \--- compileClasspath

com.google.guava:guava-jdk5:17.0
\--- com.google.api-client:google-api-client:1.23.0
     +--- com.google.endpoints:endpoints-framework:2.0.10
     |    \--- compileClasspath
     +--- com.google.apis:google-api-services-androidpublisher:v2-rev48-1.23.0
     |    \--- compileClasspath
     +--- com.google.api-client:google-api-client-appengine:1.23.0
     |    +--- com.google.endpoints:endpoints-framework:2.0.10 (*)
     |    \--- com.google.appengine.tools:appengine-gcs-client:0.7
     |         \--- compileClasspath
     +--- com.google.api-client:google-api-client-servlet:1.23.0
     |    \--- com.google.api-client:google-api-client-appengine:1.23.0 (*)
     \--- com.google.apis:google-api-services-storage:v1-rev108-1.22.0
          \--- com.google.appengine.tools:appengine-gcs-client:0.7 (*)

(*) - dependencies omitted (listed previously)

战争中的 WEB-INF/lib 文件:

annotations-12.0.jar
appengine-api-1.0-sdk-1.9.60.jar
appengine-gcs-client-0.7.jar
cglib-nodep-3.1.jar
commons-codec-1.6.jar
commons-lang3-3.3.2.jar
commons-logging-1.1.3.jar
endpoints-framework-2.0.10.jar
google-api-client-1.23.0.jar
google-api-client-appengine-1.23.0.jar
google-api-client-servlet-1.23.0.jar
google-api-services-androidpublisher-v2-rev48-1.23.0.jar
google-api-services-storage-v1-rev108-1.22.0.jar
google-http-client-1.23.0.jar
google-http-client-appengine-1.23.0.jar
google-http-client-jackson2-1.23.0.jar
google-http-client-jdo-1.23.0.jar
google-oauth-client-1.23.0.jar
google-oauth-client-appengine-1.23.0.jar
google-oauth-client-servlet-1.23.0.jar
gson-2.7.jar
guava-20.0.jar
guava-jdk5-17.0.jar
hamcrest-core-1.1.jar
hashids-1.0.1.jar
httpclient-4.3.4.jar
httpcore-4.3.2.jar
httpmime-4.3.4.jar
jackson-annotations-2.6.4.jar
jackson-core-2.6.4.jar
jackson-databind-2.6.4.jar
jackson-dataformat-yaml-2.4.5.jar
jackson-datatype-joda-2.4.5.jar
javax.inject-1.jar
jdo2-api-2.3-eb.jar
joda-time-2.9.9.jar
json-20140107.jar
json-simple-1.1.1.jar
jsonic-1.2.11.jar
jsr305-3.0.1.jar
jstl-1.2.jar
junit-4.10.jar
language-detector-0.6.jar
objectify-5.1.21.jar
sendgrid-java-2.2.2.jar
slf4j-api-1.7.25.jar
slf4j-jdk14-1.7.25.jar
slf4j-nop-1.7.21.jar
smtpapi-java-1.2.0.jar
snakeyaml-1.12.jar
stripe-java-5.27.0.jar
swagger-annotations-1.5.9.jar
swagger-core-1.5.9.jar
swagger-models-1.5.9.jar
transaction-api-1.1.jar
validation-api-1.1.0.Final.jar

更新 2018-01-04

输出gradle dependencyInsight --dependency guava-jdk5

com.google.guava:guava-jdk5:17.0
\--- com.google.api-client:google-api-client:1.23.0
     +--- com.google.endpoints:endpoints-framework:2.0.10
     |    \--- compileClasspath
     +--- com.google.apis:google-api-services-androidpublisher:v2-rev48-1.23.0
     |    \--- compileClasspath
     +--- com.google.api-client:google-api-client-appengine:1.23.0
     |    +--- com.google.endpoints:endpoints-framework:2.0.10 (*)
     |    \--- com.google.appengine.tools:appengine-gcs-client:0.7
     |         \--- compileClasspath
     +--- com.google.api-client:google-api-client-servlet:1.23.0
     |    \--- com.google.api-client:google-api-client-appengine:1.23.0 (*)
     \--- com.google.apis:google-api-services-storage:v1-rev108-1.22.0
          \--- com.google.appengine.tools:appengine-gcs-client:0.7 (*)

(*) - dependencies omitted (listed previously)
4

1 回答 1

0

从以下包中删除 guava-jdk5 的所有依赖项后解决了问题:

compile('com.google.endpoints:endpoints-framework:2.0.10') {
    exclude group: 'com.google.guava', module: 'guava-jdk5'
}
compile('com.google.appengine.tools:appengine-gcs-client:0.7') {
    exclude group: 'com.google.guava', module: 'guava-jdk5'
}
compile('com.google.apis:google-api-services-androidpublisher:v2-rev48-1.23.0') {
    exclude group: 'com.google.guava', module: 'guava-jdk5'
}

如果删除导致任何类型的问题,我会发布更新。

于 2018-01-11T08:40:32.633 回答