【问题标题】:build all Spring Boot apps docker(OCI) images with Spring Boot Maven Plugin in one multi-module project在一个多模块项目中使用 Spring Boot Maven 插件构建所有 Spring Boot 应用程序 docker(OCI) 映像
【发布时间】:2021-03-24 03:37:28
【问题描述】:

我有 maven 多模块项目,其中大多数模块是 Spring Boot 应用程序, 以及一些在 Spring 应用程序之间共享的 common 模块。

     <modules>
        <module>A</module>
        <module>B</module>
        <module>common</module>
        <module>D</module>
    </modules>

现在,当我想使用 spring-boot:build-image 为 Spring 应用程序构建 docker(OCI) 映像时,例如

mvn --projects A,B,D --also-make clean install org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image

maven 仍然为每个 common 模块运行 build-image 目标,这有点矫枉过正: 这些common 模块应该作为罐子构建和使用。

(插件目标必须是像org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image这样的长格式,因为在根(父)级别没有定义spring-boot插件)。

如何在一个mvn一行中构建项目中的所有Spring Boot应用,而不是一个一个?


当然,每个 Spring Boot 应用程序模块都有 spring-boot-maven-plugin 插件定义和配置,如 https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#using-import 所述

3.2。在没有父 POM 的情况下使用 Spring Boot

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

【问题讨论】:

  • 只将spring-boot-maven-plugin应用到应该是可运行jar的项目,否则不要应用它。
  • 原来如此。这就是为什么调用插件目标必须像 org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image 这样的长格式,因为在根(父)级别没有定义 spring-boot,所以 maven 会告诉比“spring-boot”未知。常用模块不依赖spring。
  • 如果您在父项目中定义了spring boot插件,它将应用于使用该父项目的所有模块。
  • 我放了(插件目标必须是像org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image这样的长格式,因为在根(父)级别没有定义spring-boot插件)。进入问题,很明显,父级没有spring-boot插件
  • 如果项目中定义了插件,它也会被应用,否则插件不会被应用。

标签: java spring maven spring-boot-maven-plugin


【解决方案1】:

似乎不可能在一个命令中完成, 所以不得不

mvn clean install
mvn --projects A spring-boot:build-image
mvn --projects B spring-boot:build-image
mvn --projects D spring-boot:build-image

【讨论】:

    猜你喜欢
    • 2020-11-14
    • 2015-10-10
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 2016-09-13
    • 2018-09-21
    相关资源
    最近更新 更多