如何通过Maven部署Quarkus Runner Jar及Native镜像?
解决Quarkus Runner Jar及Native镜像的Maven部署问题
嘿,我来帮你搞定这个Quarkus Runner Jar部署的问题!你之前用maven-deploy-plugin的deploy-file目标没成功,是因为这个目标本来是用来部署外部文件的,不是项目构建过程中生成的文件,没法自动关联到你的构建生命周期里。下面给你两个简便的方案:
一、部署Quarkus Runner Jar
最省心的方式是用build-helper-maven-plugin把Runner Jar标记为项目的附加构件,这样执行mvn deploy时会自动把它和常规jar、pom一起部署到仓库。
在你的pom.xml里添加以下插件配置:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.3.0</version> <executions> <execution> <id>attach-runner-jar</id> <phase>package</phase> <goals> <goal>attach-artifact</goal> </goals> <configuration> <artifacts> <artifact> <!-- 用项目变量自动定位Runner Jar,不用硬编码路径 --> <file>${project.build.directory}/${project.build.finalName}-runner.jar</file> <type>jar</type> <!-- 给Runner Jar加个classifier,方便仓库里区分常规jar --> <classifier>runner</classifier> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>
配置完成后,只需要执行常规的mvn clean deploy,Maven就会自动把xxx-runner.jar(带runner classifier)部署到你的仓库里,完全不用额外命令参数。
二、部署Quarkus Native镜像
Native镜像的部署逻辑和Runner Jar类似,也是用build-helper-maven-plugin把它附加为项目构件,注意不同平台的Native镜像文件名和类型会有差异:
1. Linux/macOS平台的配置
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.3.0</version> <executions> <execution> <id>attach-native-binary</id> <phase>package</phase> <goals> <goal>attach-artifact</goal> </goals> <configuration> <artifacts> <artifact> <file>${project.build.directory}/${project.build.finalName}-runner-native</file> <type>bin</type> <classifier>native</classifier> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>
2. Windows平台的配置
Windows下Native镜像会生成.exe后缀的文件,只需要修改<file>和<type>:
<artifact> <file>${project.build.directory}/${project.build.finalName}-runner-native.exe</file> <type>exe</type> <classifier>native</classifier> </artifact>
如果需要跨平台构建,你可以用Maven的profile来区分不同平台的配置,这样不用手动修改文件。
执行mvn clean package -Pnative构建Native镜像后,再执行mvn deploy,就能把Native镜像部署到仓库里了。
内容的提问来源于stack exchange,提问作者Rolintocour
相关产品推荐
相关产品推荐

