在 App Engine 的 Cloud Endpoints Frameworks 2.0 中增强端点

Enhancing endpoints in Cloud Endpoints Frameworks 2.0 for App Engine

我收到了一封来自 GCP 的电子邮件,要求我将我的项目从 Cloud Endpoints 1.0 迁移到 Cloud Endpoints Frameworks 2.0。

我已按照此处列出的步骤操作:https://cloud.google.com/appengine/docs/java/endpoints/migrating?authuser=0

在我之前的 build.gradle 中,我有这个指令来增强我的端点并且它工作正常:

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
    enhancer {
        version = "v2"
        api="jdo"  // or "jpa"
        enhanceOnBuild = true
    }
}

但是,在迁移和编译之后,出现以下错误:

Error:(60, 0) Could not find method enhancer() for arguments [build_2dn4fni12bkrsqgsi25gsx3hh$_run_closure2$_closure7@6b02ee9e] on object of type com.google.cloud.tools.gradle.appengine.core.AppEngineExtension.

如果我删除 enhancer 部分,我会收到以下错误:

org.datanucleus.metadata.MetaDataManager initialiseFileMetaDataForUse: Found Meta-Data for class [...] but this class is not enhanced!! Please enhance the class before running DataNucleus.

那么,新框架的等效增强是什么? (我正在使用 Android Studio 2.3.3)

我直接从 Google 云支持那里得到了这个回复:

There are some features and tools that are excluded and currently unavailable with the latest version of Endpoints v2. If your application requires any of the below mentioned, you are not recommended to migrate.

  • JSON-RPC protocol, which is required for legacy iOS clients
  • Automatic ETags
  • Automatic Kind fields
  • IDE integration
  • fields partial responses

Meanwhile, below are the tools that are currently not supported in v2.0:

  • Android Studio support for Cloud Endpoints 1.0
  • Android Studio code validation and quick fixes for Cloud Endpoints 1.0

So, with regards to the 'enhancer' method, have you checked if this is included on the aforementioned features? If so, the only way for you to do is check for an equivalent function or downgrade again to v1.0.

这不是我希望的答案,但至少在他们正式支持这些功能之前,我们不应该迁移到 Endpoints Framework v2.0。

问题是新的 gradle 插件没有 appengineEnhance 任务,这是为 jpa/jdo 增强 类 所必需的。

这里有一个解决方法

appengine 块中的 enhancer {...} 部分不需要,并且应该在上面的 link 中的脚本中完成配置。