Google Cloud Function 无法使用 FAT jar 进行部署

问题描述 投票:0回答:1

我有一个 Google 云功能 (v2),它依赖于并使用名为“base.jar”的私有 JAR。 Base.jar 包含我们应用程序的一堆数据库类,并在多个模块之间共享,包括这个名为“share.jar”的云函数。

我正在按照此处的说明构建和部署 FAT jar。

https://cloud.google.com/functions/docs/concepts/java-deploy

执行

mvn clean package
gcloud functions deploy ...
后,出现这个错误:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed with status: FAILURE and message: [ERROR] Failed to execute goal on project Share: Could not resolve dependencies for project com.app.share:Share:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: com.app:Base:jar:1.0-SNAPSHOT (absent): Could not find artifact com.app:Base: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. For more details see the logs at https://console.cloud.google.com/cloud-build/builds;region=us-central1/94b76cd9-4b53-4427-a23d-2d5975c6164d?project=361612196006.

这是 pom。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.app.share</groupId>
    <artifactId>Share</artifactId>
    <version>0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- Required for Function primitives -->
        <dependency>
            <groupId>com.google.cloud.functions</groupId>
            <artifactId>functions-framework-api</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.app</groupId>
            <artifactId>Base</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!--
                  Google Cloud Functions Framework Maven plugin

                  This plugin allows you to run Cloud Functions Java code
                  locally. Use the following terminal command to run a
                  given function locally:

                  mvn function:run -Drun.functionTarget=your.package.yourFunction
                -->
                <groupId>com.google.cloud.functions</groupId>
                <artifactId>function-maven-plugin</artifactId>
                <version>0.11.0</version>
                <configuration>
                    <functionTarget>com.app.share.Share</functionTarget>
                </configuration>
            </plugin>

            <!-- Incorporates external jars. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals><goal>shade</goal></goals>
                        <configuration>
                            <outputFile>${project.build.directory}/deployment/${build.finalName}.jar</outputFile>
                            <transformers>
                                <!-- This may be needed if you need to shade a signed JAR -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                                    <resource>.SF</resource>
                                    <resource>.DSA</resource>
                                    <resource>.RSA</resource>
                                </transformer>
                                <!-- This is needed if you have dependencies that use Service Loader. Most Google Cloud client libraries does. -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

请注意,这个“共享”项目是父pom的一个模块,其中包括“Base”和“Share”模块。

家长

  • 基地
  • 分享

无论如何,在 clean/install 之后,我可以看到目标目录有一个 JAR,但没有包含来自 Base 的类。但是,部署目录有一个 JAR,其中包含 Base 中的类。因此,我删除了第一个 JAR 并运行

google cloud deploy
,但仍然出现错误。

更新 1:根据 Janez 的评论,这里是引用父项目的 pom。出现类似问题。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.app</groupId>
        <artifactId>Parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
 
    <groupId>com.app.share</groupId>
    <artifactId>Share</artifactId>
    <version>0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- Required for Function primitives -->
        <dependency>
            <groupId>com.google.cloud.functions</groupId>
            <artifactId>functions-framework-api</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.app</groupId>
            <artifactId>Base</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!--
                  Google Cloud Functions Framework Maven plugin

                  This plugin allows you to run Cloud Functions Java code
                  locally. Use the following terminal command to run a
                  given function locally:

                  mvn function:run -Drun.functionTarget=your.package.yourFunction
                -->
                <groupId>com.google.cloud.functions</groupId>
                <artifactId>function-maven-plugin</artifactId>
                <version>0.11.0</version>
                <configuration>
                    <functionTarget>com.app.share.Share</functionTarget>
                </configuration>
            </plugin>

            <!-- Incorporates external jars. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals><goal>shade</goal></goals>
                        <configuration>
                            <outputFile>${project.build.directory}/deployment/${build.finalName}.jar</outputFile>
                            <transformers>
                                <!-- This may be needed if you need to shade a signed JAR -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                                    <resource>.SF</resource>
                                    <resource>.DSA</resource>
                                    <resource>.RSA</resource>
                                </transformer>
                                <!-- This is needed if you have dependencies that use Service Loader. Most Google Cloud client libraries does. -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这是“gcloud deploy function...”的输出

错误:(gcloud.functions.deploy)操作错误:代码= 3,消息=构建失败,状态:失败和消息:[错误] [错误]处理POM时遇到一些问题: [致命] com.app.share:Share:0.1-SNAPSHOT 的不可解析父 POM:无法解析以下工件:com.app:Parent:pom:1.0-SNAPSHOT(不存在):找不到工件 com. app:Parent:pom:1.0-SNAPSHOT 和 'parent.relativePath' 指向错误的本地 POM @ 第 7 行,第 13 列

没有parent-1.0-SNAPSHOT.jar。 Parent是顶级项目pom!!!

maven google-cloud-functions maven-multi-module
1个回答
0
投票

似乎通过更新 gcloud CLI 解决了该问题。我当时用的是v458。更新到当前版本v463,似乎已经解决了问题。如果我发现问题,我会在这里进一步发帖。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.