我的云函数代码,是一个maven jar项目。它依赖于其他内部maven jar,所以我已经将该依赖项添加到pom.xml中
预期:我预计依赖的jar将自动包含在云功能部署中,但我得到了一个错误";找不到工件";。本地编译&跑步没有任何问题。
我不想将那些依赖源代码直接复制粘贴到我的gcloud-maven项目中。[坏]
[INFO] Installing <removed>-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.659 s
[INFO] Finished at: 2021-04-10T16:31:39-04:00
[INFO] ------------------------------------------------------------------------
>gcloud functions deploy response-adapter --entry-point fun.pubsub.<removed> --runtime java11 --memory 512MB --trigger-topic <removed>
--env-vars-file env.yml
Deploying function (may take a while - up to 2 minutes)...-
For Cloud Build Stackdriver Logs, visit:
Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: ...maven-plugin-2.2.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/google/cloud/tools/appengine-plugins-core/0.8.1/appengine-plugins-core-0.8.1.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/google/inject/guice/4.2.1/guice-4.2.1-no_aop.jar (521 kB at 375 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/yaml/snakeyaml/1.21/snakeyaml-1.21.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar (502 kB at 357 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/google/cloud/tools/appengine-maven-plugin/2.2.0/appengine-maven-plugin-2.2.0.jar (76 kB at 53 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.19/commons-compress-1.19.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/google/cloud/tools/appengine-plugins-core/0.8.1/appengine-plugins-core-0.8.1.jar (236 kB at 164 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/commons-io/commons-io/2.5/commons-io-2.5.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar (85 kB at 59 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/yaml/snakeyaml/1.21/snakeyaml-1.21.jar (299 kB at 205 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.19/commons-compress-1.19.jar (615 kB at 416 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/commons-io/commons-io/2.5/commons-io-2.5.jar (209 kB at 141 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/google/cloud/functions/invoker/java-function-invoker/1.0.2/java-function-invoker-1.0.2.jar (4.2 MB at 2.6 MB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.127 s
[INFO] Finished at: 2021-04-10T20:35:09Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project gcf-removed-adapter: Could not resolve dependencies for project gcf-demo:gcf-removed-adapter:jar:0.0.1-SNAPSHOT: Could not find artifact myadaptor:removed-mapper:jar:1.0-
SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException; Error ID: efa79f31
要实现这一点,您需要从JAR进行部署。像这样,您创建了一个JAR,其中已经包含了所有的依赖项(maven shade(。在部署时没有解决方案,只获取JAR并将其放入云函数中。