首页 > 解决方案 > 使用私有依赖项部署 Cloud Function

问题描述

这是我的第一个问题,所以我会尽力使它变得更好。

我的团队使用一些通用类(使用 maven 来管理依赖项)部署了多个 Java Cloud Functions (GCP)。现在这些类在每个函数中都是重复的,并且必须在每次代码编辑时到处更新。每个 Cloud Functions 都是从源代码部署的。为了避免重复这些类,我将它们打包在一个 jar 中,一切都在本地运行良好。--source我将此 jar 添加为每个 Cloud Function pom 文件中的本地依赖项,并尝试通过构建具有所有依赖项的 jar 并在gcloud deploy. 这会导致似乎是 jar 上传的超时错误。

错误跟踪:

DEBUG: Starting new HTTPS connection (1): storage.googleapis.com:443
DEBUG: Caught socket error, retrying: ('Connection aborted.', timeout('The write operation timed out',))

到目前为止我尝试了什么:

详细错误:

[ERROR] Failed to execute goal on project get-content: Could not resolve dependencies for project project:cf:jar:1.0: Failed to collect dependencies at project:pipeline:jar:0.0.1: Failed to read artifact descriptor for project:pipeline:jar:0.0.1: Could not transfer artifact project:pipeline:pom:0.0.1 from/to project-nexus (XXX): Cannot access XXX with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access XXX using the registered transporter factories: WagonTransporterFactory: Unsupported transport protocol -> [Help 1]

我相信这只是因为我的 jar 依赖项太大而无法上传,因为我实际上首先错误地部署了没有依赖关系的 jar(部署成功,但在执行期间缺少类定义)。我的问题是如何使用一个本地/私有依赖项部署我的云功能?

笔记 :

标签: javamavengoogle-cloud-functions

解决方案


我通过从 Maven 切换到 Gradle 解决了这个问题。问题是 Maven 将存储库身份验证参数存储在~/.m2/settings.xmlGoogle Build 在构建我的 Cloud Function 以进行部署时无法访问的本地文件中。在这个问题之后,我直接切换到 Gradle 以在gradle.build文件中提供身份验证。


推荐阅读