feat: 初始化 jpackage-maven-plugin 通用原生打包插件
基于 OpenJDK 16+ 官方 jpackage 工具,将任意标准 Java 应用打包为内嵌最小运行时的
跨平台自包含应用镜像(app-image 绿色免安装版),不绑定任何应用框架。
核心能力:
- 零配置:自动从主 JAR 的 META-INF/MANIFEST.MF 探测 Main-Class
- 环境定位:优先 ${java.home}/bin/jpackage,兼容 JRE 布局、JAVA_HOME 与 PATH
- 输入目录隔离:使用独立的 target/jpackage-input,避免编译产物被误打包
- 版本清洗:1.0.0-SNAPSHOT 等 Maven 版本号自动转为 jpackage 合法版本
- 编码防御:默认注入全套 UTF-8 运行参数,规避跨平台中文乱码
- 平台自适应:--win-console 仅在 Windows 目标平台传递
- 启动脚本:生成 run.sh(755)与 CRLF 换行的 run.bat(含 chcp 65001)
- Wine 交叉打包:支持在 Linux 上借助 Wine 产出 Windows 应用镜像
交付内容:
- 插件工程与面向 Maven Central 的完整 pom 配置
- 核心 Mojo 与 10 个 internal 工具类
- 103 个单元测试用例
- examples/hello-cli 可运行示例与中文 README
Generated with AI
Co-Authored-By: zkh <zkh@mirenqinggege.com>
This commit is contained in:
@@ -0,0 +1,344 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mirenqinggege.maven</groupId>
|
||||
<artifactId>jpackage-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>JPackage Maven Plugin</name>
|
||||
<description>
|
||||
通用原生打包插件:基于 OpenJDK 16+ 官方 jpackage 工具,将任意标准 Java 应用打包为
|
||||
内嵌最小运行时的跨平台自包含应用镜像(app-image,解压即用、目标机器无需安装 Java)。
|
||||
插件不绑定任何应用框架,自动探测 Main-Class、自动清洗版本号、按平台自适应参数并生成
|
||||
一键启动脚本。
|
||||
</description>
|
||||
<inceptionYear>2026</inceptionYear>
|
||||
|
||||
<url>https://git.mirenqinggege.com/zkh/jpackage-maven-plugin</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>一个 OSI 认可的开源许可证。</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>zkh</id>
|
||||
<name>zkh</name>
|
||||
<email>zkh@mirenqinggege.com</email>
|
||||
<roles>
|
||||
<role>Developer</role>
|
||||
<role>Maintainer</role>
|
||||
</roles>
|
||||
<timezone>Asia/Shanghai</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:ssh://git@git.mirenqinggege.com:2222/zkh/jpackage-maven-plugin.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@git.mirenqinggege.com:2222/zkh/jpackage-maven-plugin.git</developerConnection>
|
||||
<url>https://git.mirenqinggege.com/zkh/jpackage-maven-plugin</url>
|
||||
<tag>jpackage-maven-plugin-1.0.0</tag>
|
||||
</scm>
|
||||
|
||||
<issueManagement>
|
||||
<system>Gitea Issues</system>
|
||||
<url>https://git.mirenqinggege.com/zkh/jpackage-maven-plugin/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
|
||||
<!-- 编译插件所用到的 Maven API 版本(provided,运行时由 Maven 自身提供) -->
|
||||
<maven.version>3.9.9</maven.version>
|
||||
<maven.plugin.tools.version>3.16.0</maven.plugin.tools.version>
|
||||
<maven.compiler.version>3.14.0</maven.compiler.version>
|
||||
<maven.surefire.version>3.5.2</maven.surefire.version>
|
||||
<maven.jar.version>3.4.2</maven.jar.version>
|
||||
<maven.source.version>3.3.1</maven.source.version>
|
||||
<maven.javadoc.version>3.12.0</maven.javadoc.version>
|
||||
<maven.gpg.version>3.2.8</maven.gpg.version>
|
||||
<maven.enforcer.version>3.6.3</maven.enforcer.version>
|
||||
<central.publishing.version>0.12.0</central.publishing.version>
|
||||
|
||||
<junit.version>5.14.4</junit.version>
|
||||
</properties>
|
||||
|
||||
<prerequisites>
|
||||
<maven>3.6.3</maven>
|
||||
</prerequisites>
|
||||
|
||||
<dependencies>
|
||||
<!-- Maven 插件基础 API -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- MavenProject / 运行时模型,插件在 Maven 容器内运行时由 Maven 提供 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Mojo 注解处理器(仅编译期需要) -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>${maven.plugin.tools.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 测试 -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 校验构建环境:Maven 版本、JDK 版本,避免产出无法被消费的构件 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>${maven.enforcer.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-build-environment</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>[3.6.3,)</version>
|
||||
</requireMavenVersion>
|
||||
<requireJavaVersion>
|
||||
<version>[17,)</version>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven.compiler.version}</version>
|
||||
<configuration>
|
||||
<release>${maven.compiler.release}</release>
|
||||
<encoding>UTF-8</encoding>
|
||||
<!-- 生成方法参数名,便于 Maven 在调试与诊断时输出更可读的信息 -->
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>${maven.plugin.tools.version}</version>
|
||||
<configuration>
|
||||
<!-- 插件 goal 前缀:使用 mvn jpackage:package-app 调用 -->
|
||||
<goalPrefix>jpackage</goalPrefix>
|
||||
<!-- 使用注解处理器生成 plugin.xml,避免额外的 XML 描述文件 -->
|
||||
<skipErrorNoDescriptorsFound>false</skipErrorNoDescriptorsFound>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-descriptor</id>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>descriptor</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>help-goal</id>
|
||||
<goals>
|
||||
<goal>helpmojo</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven.surefire.version}</version>
|
||||
</plugin>
|
||||
|
||||
<!-- Maven Central 要求:随主构件一同发布 sources jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${maven.source.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Maven Central 要求:随主构件一同发布 javadoc jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${maven.javadoc.version}</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
<charset>UTF-8</charset>
|
||||
<locale>zh_CN</locale>
|
||||
<doclint>none</doclint>
|
||||
<quiet>true</quiet>
|
||||
<notimestamp>true</notimestamp>
|
||||
<!-- 不让他人项目的依赖出现在本项目的 javadoc 链接中 -->
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
<detectLinks>false</detectLinks>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Maven Central 要求:所有构件必须附带 GPG 签名。
|
||||
默认 profile(default-no-release)会把该执行置为 phase=none,
|
||||
因此日常 mvn install / mvn verify 不会触发签名;
|
||||
发布时使用 mvn clean deploy -P release 激活签名。 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>${maven.gpg.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!--
|
||||
发布到 Maven Central 的官方插件(Sonatype Central Portal)。
|
||||
发布命令:mvn clean deploy -P release
|
||||
|
||||
首次使用前需:
|
||||
1. 在 https://central.sonatype.com 注册命名空间(如 com.mirenqinggege);
|
||||
2. 在 ~/.m2/settings.xml 中配置 server:
|
||||
<server>
|
||||
<id>central</id>
|
||||
<username>Portal Token 的用户名</username>
|
||||
<password>Portal Token 的密码</password>
|
||||
</server>
|
||||
-->
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>${central.publishing.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<!--
|
||||
false:构件上传并校验通过后停留在 Portal 的“待发布”状态,由人工确认后再点 Publish。
|
||||
熟悉流程后可改为 true 实现校验通过即自动发布。
|
||||
-->
|
||||
<autoPublish>false</autoPublish>
|
||||
<!-- 等待 Portal 完成校验,校验不通过会直接以失败退出并给出原因 -->
|
||||
<waitUntil>validated</waitUntil>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<!--
|
||||
发布专用 profile:mvn clean deploy -P release
|
||||
激活后启用 GPG 签名(显式指定密钥),日常构建不受影响。
|
||||
-->
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<properties>
|
||||
<!-- 可通过 -Dgpg.keyname=xxx 覆盖 -->
|
||||
<gpg.keyname>A29C55F143AA11321B87D9F402253AEB01AD4266</gpg.keyname>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<keyname>${gpg.keyname}</keyname>
|
||||
<!-- 关闭 GPG 代理的图形弹窗,便于 CI 中非交互执行 -->
|
||||
<pinentryMode>loopback</pinentryMode>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<!-- 默认构建不签名:把 gpg 的 sign 执行停用 -->
|
||||
<profile>
|
||||
<id>default-no-release</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
Reference in New Issue
Block a user