You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在单次Maven构建中生成两个独立的Quarkus Runner JAR

多模块Maven项目中生成两个独立Quarkus Runner Uber-JAR的需求

我在多模块Maven项目中使用Quarkus,需要在单次反应堆构建中生成两个独立的Quarkus Runner JAR:

  • quarkus-service-soft-runner.jar:Quarkus Runner Uber-JAR,仅包含quarkus-crypto-soft(不含crypto-hsm)
  • quarkus-service-hsm-runner.jar:Quarkus Runner Uber-JAR,仅包含quarkus-crypto-hsm(不含crypto-soft)

背景

父POM中已配置quarkus-maven-plugin执行build、generate-code、generate-code-tests目标,配置如下:

<plugin>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-maven-plugin</artifactId>
    <version>3.27.1.redhat-00001</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <goals>
                <goal>build</goal>
                <goal>generate-code</goal>
                <goal>generate-code-tests</goal>
            </goals>
        </execution>
    </executions>
</plugin>

服务模块中已声明acs-quarkus-crypto-soft和acs-quarkus-crypto-hsm依赖。

尝试的方案及问题

  1. 使用maven-assembly-plugin的两个执行实例,通过jar-with-dependencies和dependencySet/excludes构建两个胖JAR,但生成的JAR不是有效的Quarkus Runner JAR,无法正常运行。
  2. 在服务模块中通过Maven Profile配置两次Quarkus插件执行,设置finalName和quarkus.package.type为uber-jar,但遇到配置错误(如“Element quarkus.package.type is not allowed here”或“Element excludes is not allowed here”),且父插件的代码生成有时会在Runner JAR生成前执行,导致构建失败。

当前的Profile配置如下:

<profile>
    <id>crypto-soft</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <dependencies>
        <dependency>
            <groupId>com.crypto</groupId>
            <artifactId>crypto-soft</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <finalName>quarkus-service-soft-runner</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>
<profile>
    <id>crypto-hsm</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <dependencies>
        <dependency>
            <groupId>com.crypto</groupId>
            <artifactId>crypto-hsm</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <finalName>quarkus-service-hsm-runner</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

构建时出现错误:Quarkus code generation phase has failed

需求

需要一个简洁、符合Quarkus规范的解决方案,在单次构建中生成两个可运行的Quarkus Uber-JAR,无需修改父POM的代码生成流程或使用临时方案。


内容的提问来源于stack exchange,提问作者SBW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 22:14:52