【问题标题】:Maven multi-project build with API modules does not seem to include project-level dependencies in build image带有 API 模块的 Maven 多项目构建似乎没有在构建映像中包含项目级依赖项
【发布时间】:2019-07-30 02:04:12
【问题描述】:

您好,我有一个 springboot 多项目 maven 构建,它构建多个图像。结构类似于:

- project-parent
   - common
   - project-b-parent
      - project-b-api
      - project-b-gateway
      - project-b-launcher
   - project-c-parent
      - project-c-api
      - project-c-gateway
      - project-c-launcher

其中 *launcher 模块是我的 springboot uber jar,网关是 spring mvc 控制器和支持类,而 apis 是启动器模块中的项目级依赖项。例如 project-c 依赖于 project-b-api

我的项目父 pom 有:

   ...
   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
   </parent>
   <version>0.0.1-SNAPSHOT</version>
   <groupId>my.group</groupId>
   <artifactId>project-parent</artifactId>
   <packaging>pom</packaging>
   ...
   <modules>
        <module>project-b-parent</module>
        <module>project-c-parent</module>
    </modules>
    ...
    <properties>
        <jib.skip>true</jib.skip>
    </properties>
    ...
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.google.cloud.tools</groupId>
                        <artifactId>jib-maven-plugin</artifactId>
                        <version>1.0.0</version>
                        <configuration>
                            <from>
                                <image>my.base.image:latest</image>
                            </from>
                            <to>
                                <image>my.image.registry/${project-name}</image>
                                <tags>
                                    <tag>${project.version}</tag>
                                    <tag>latest</tag>
                                </tags>
                            </to>
                            <allowInsecureRegistries>true</allowInsecureRegistries>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

请注意,我已将 &lt;jib.skip&gt;true&lt;/jib.skip&gt; 添加到我的父 pom.xml 中。我在启动器中有&lt;jib.skip&gt;false&lt;/jib.skip&gt;,这会产生仅从 *launcher 模块创建图像的预期行为。

所有模块的版本均为 0.0.1-SNAPSHOT。

当我使用潜水检查我的图像时,我没有 SNAPSHOT DEPENDENCIES 层,并且我的项目级依赖项似乎不在图像中。

当我运行我的应用程序时,它们似乎启动了 SpringBoot 并侦听端口,但控制器的端点没有加载。另一个项目在尝试从项目级依赖项加载类时抛出 NoClassDefFoundError 异常。

我已尝试将所有内容版本化为 0.0.1,而不使用 SNAPSHOT,并且我的项目级依赖项不包含在我的依赖项层中。

我也尝试过运行mvn -X -DjibSerialize=true clean compile jib:build &gt; logs.txt 和我的类级依赖项

...
[INFO] --- jib-maven-plugin:1.0.0:build (default-cli) @ project-b-launcher ---
[DEBUG] Configuring mojo com.google.cloud.tools:jib-maven-plugin:1.0.0:build from plugin realm ClassRealm[plugin>com.google.cloud.tools:jib-maven-plugin:1.0.0, parent: sun.misc.Launcher$AppClassLoader@5c647e05]
[DEBUG] Configuring mojo 'com.google.cloud.tools:jib-maven-plugin:1.0.0:build' with basic configurator -->
[DEBUG]   (f) allowInsecureRegistries = true
[DEBUG]   (f) mainClass = project-b.stuff.ApplicationKt
[DEBUG]   (f) container = com.google.cloud.tools.jib.maven.JibPluginConfiguration$ContainerParameters@77662d13
[DEBUG]   (f) image = my.registry/distroless-java:latest
[DEBUG]   (f) from = com.google.cloud.tools.jib.maven.JibPluginConfiguration$FromConfiguration@6a0328d7
[DEBUG]   (f) project = MavenProject: my.company:project-a-launcher:0.0.1 @ C:\my-programs\project-parent\project-b-parent\project-b-launcher\pom.xml
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@51ec2df1
[DEBUG]   (f) skip = false
[DEBUG]   (f) image = my-new-image
[DEBUG]   (f) tags = [0.0.1, latest]
[DEBUG]   (f) to = com.google.cloud.tools.jib.maven.JibPluginConfiguration$ToConfiguration@6370bf52
[DEBUG] -- end configuration --
[INFO] 
[INFO] Containerizing application to my.registry\project-parent\project-b-parent\project-b-launcher, my.registry\project-parent\project-b-parent\project-b-launcher\customer-launcher\project-b-launcher:0.0.1-SNAPSHOT, my.registry\project-parent\project-b-parent\project-b-launcher\customer-launcher\project-b-launcher...
[DEBUG] Containerizing application with the following files:
[DEBUG]     Dependencies:
[DEBUG]         C:\my-programs\project-parent\project-c-parent\project-c-gateway\target\classes
[DEBUG]         C:\my-programs\project-parent\project-c-parent\project-c-api\target\classes
[DEBUG]         C:\Users\me\.m2\repository\org\springframework\spring-web\5.1.4.RELEASE\spring-web-5.1.4.RELEASE.jar
...

请注意,我在此 DEBUG 日志输出中重命名了许多敏感目录等。 我不确定第二条和第三条底线(项目级依赖项)是否应该指向 target\classes\ - 他们应该引用 .jars 吗?如果我只做一个 mvn compile jib:build

,我想他们不能

我希望我已将其发布在正确的位置。

【问题讨论】:

    标签: java maven kotlin jib


    【解决方案1】:

    事实证明,OP 的项目设置存在问题。 (https://github.com/GoogleContainerTools/jib/issues/1539 中的详细信息。)基本上,spring-boot-maven-pluginjib-maven-plugin 都应用于根 pom.xml。这导致

    • spring-boot-maven-plugin 试图为每个子模块创建一个可运行的 JAR,其中一些是没有主类的库。
    • jib-maven-plugin 尝试为每个子模块以及顶级项目构建映像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2013-10-03
      • 2018-09-08
      • 2020-05-08
      • 2011-05-11
      相关资源
      最近更新 更多