将Cloud Endpoints Framework v2升级到Java 8后出现API错误

时间:2017-12-28 10:34:43

标签: java google-app-engine google-cloud-endpoints google-cloud-endpoints-v2

我尝试将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):

backend.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)
        }
    }
}

project.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)

1 个答案:

答案 0 :(得分:0)

After removing all dependencies of guava-jdk5 from following packages solved the problem:

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

I'll post an update if the removal leads to any kind of problems.