使用API​​模块进行Maven多项目构建似乎在构建映像中不包含项目级依赖项

时间:2019-03-08 03:49:09

标签: java maven kotlin jib

你好,我有一个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控制器和支持类,而api是启动器模块中的项目级依赖项。例如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>

请注意,我已经将<jib.skip>true</jib.skip>添加到了我的父pom。我在启动器中安装了<jib.skip>false</jib.skip>,这创建了仅从* launcher模块创建图像的预期行为。

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

当我使用潜水检查图像时,我没有SNAPSHOT DEPENDENCIES层,并且项目级别的依存关系似乎没有出现在图像中。

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

我尝试将所有版本的版本都设置为0.0.1,但不包含SNAPSHOT,并且我的项目层依赖项未包含在我的依赖项层中。

我也尝试过运行mvn -X -DjibSerialize=true clean compile jib:build > 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
...

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

我希望将其张贴在正确的位置。

1 个答案:

答案 0 :(得分:0)

事实证明,OP的项目设置存在问题。 (有关详细信息,请参见https://github.com/GoogleContainerTools/jib/issues/1539。)基本上,let obj = { '0': [ 2, 3, 4, 7, 8, 9, 10,11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25,26,27,28,29,30,31,32 ], '3': [ 0, 1,2,3,4,5,6,7,8,9,10,11,12,13, 15,16,17,18,22,23,24 ] } function getSeq(arr,len){ let seq = [[]]; for(let i = 0;i<arr.length;i++){ seq[seq.length - 1].push(arr[i]); if(arr[i] !== arr[i+1] - 1){ seq.push([]) } } return seq.reduce((ac,a) => a.length < len ? ac: [...ac,...a],[]) } for(let key in obj){ obj[key] = getSeq(obj[key],10) } console.log(obj)spring-boot-maven-plugin都应用于根jib-maven-plugin。结果是

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